Skip to content

Commit 48ab893

Browse files
authored
Make sure multi-day event days are in order (#109)
* add test for end to match start * unorder them * pass tests
1 parent a2f169a commit 48ab893

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/Types/MultiDayEvent.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function __construct(Entry $event, private bool $collapseMultiDays)
2222
parent::__construct($event);
2323

2424
$this->days = collect($this->event->days)
25+
->sortBy('date')
2526
->map(fn (Values $day) => new Day(
2627
$day->all(),
2728
$this->timezone['timezone'],

tests/Unit/MultiDayEventsTest.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ protected function setUp(): void
3232
->data([
3333
'recurrence' => 'multi_day',
3434
'days' => [
35-
[
36-
'date' => '2019-11-23',
37-
'start_time' => '19:00',
38-
'end_time' => '21:00',
39-
],
4035
[
4136
'date' => '2019-11-24',
4237
'start_time' => '11:00',
@@ -47,6 +42,11 @@ protected function setUp(): void
4742
'start_time' => '11:00',
4843
'end_time' => '15:00',
4944
],
45+
[
46+
'date' => '2019-11-23',
47+
'start_time' => '19:00',
48+
'end_time' => '21:00',
49+
],
5050
],
5151
'timezone' => 'America/Vancouver',
5252
]);
@@ -118,6 +118,23 @@ public function canGetStart()
118118
);
119119
}
120120

121+
#[Test]
122+
public function canGetEnd()
123+
{
124+
$this->assertEquals(
125+
Carbon::parse('2019-11-25 15:00')->shiftTimezone('America/Vancouver'),
126+
$this->event->end()
127+
);
128+
$this->assertEquals(
129+
Carbon::parse('2019-11-21 23:59:59.999999')->shiftTimezone('America/Vancouver'),
130+
$this->allDayEvent->end()
131+
);
132+
$this->assertEquals(
133+
Carbon::parse('2019-11-21 23:59:00')->shiftTimezone('America/Vancouver')->timezone,
134+
$this->event->end()->timezone
135+
);
136+
}
137+
121138
#[Test]
122139
public function noOccurrencesIfNowAfterEndDate()
123140
{

0 commit comments

Comments
 (0)