Skip to content

Commit 4779f99

Browse files
committed
get all tests passing
1 parent 329ac2a commit 4779f99

File tree

6 files changed

+30
-30
lines changed

6 files changed

+30
-30
lines changed

src/Types/Event.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
abstract class Event
1616
{
17-
abstract protected function rule(): RRuleInterface;
17+
abstract protected function rule(bool $useEnd = false): RRuleInterface;
1818

1919
public function __construct(protected Entry $event) {}
2020

@@ -76,7 +76,7 @@ public function occursOnDate(string|CarbonInterface $date): bool
7676

7777
public function nextOccurrences(int $limit = 1): Collection
7878
{
79-
return $this->collect($this->rule()->getOccurrencesAfter(date: now(), inclusive: true, limit: $limit));
79+
return $this->collect($this->rule(true)->getOccurrencesAfter(date: now(), inclusive: true, limit: $limit));
8080
}
8181

8282
public function startTime(): string

src/Types/MultiDayEvent.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,8 @@ public function toICalendarEvents(): array
9393
->all();
9494
}
9595

96-
protected function rule(bool $collapseDays = false): RRuleInterface
96+
protected function rule(bool $useEnd = false): RRuleInterface
9797
{
98-
// if we're collapsing, then return an rrule instead of rset and use start of first day to end of last day
99-
if ($this->collapseMultiDays) {
100-
return new RRule([
101-
'count' => 1,
102-
'dtstart' => $this->end(),
103-
'freq' => RRule::DAILY,
104-
]);
105-
}
106-
10798
return tap(
10899
new RSet,
109100
fn (RSet $rset) => $this->days->each(fn (Day $day) => $rset->addRRule([

src/Types/RecurringEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function toICalendarEvents(): array
5252
return [$iCalEvent];
5353
}
5454

55-
protected function rule(): RRuleInterface
55+
protected function rule(bool $useEnd = false): RRuleInterface
5656
{
5757
$rule = [
5858
'dtstart' => $this->end(),

src/Types/SingleDayEvent.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@
77

88
class SingleDayEvent extends Event
99
{
10-
protected function rule(): RRuleInterface
10+
protected function rule(bool $useEnd = false): RRuleInterface
1111
{
12+
if ($useEnd) {
13+
return new RRule([
14+
'count' => 1,
15+
'dtstart' => $this->end(),
16+
'freq' => RRule::DAILY,
17+
]);
18+
}
19+
1220
return new RRule([
13-
'count' => 1,
14-
'dtstart' => $this->end(),
21+
// 'count' => 1,
22+
'dtstart' => $this->start(),
23+
'until' => $this->end(),
1524
'freq' => RRule::DAILY,
1625
]);
1726
}

tests/EventsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@
421421

422422
expect($events1)->toHaveCount(1);
423423
expect($events2)->toHaveCount(1);
424-
})->skip();
424+
});
425425

426426
test('event with timezone offset appears on the correct UTC date', function () {
427427
$date = CarbonImmutable::createFromDate(2026, 2, 28);

tests/Types/SingleDayEventsTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Carbon\Carbon;
66
use Carbon\CarbonImmutable;
77
use Carbon\CarbonTimeZone;
8+
use Illuminate\Support\Facades\Date;
89
use Statamic\Facades\Entry;
910
use TransformStudios\Events\EventFactory;
1011
use TransformStudios\Events\Types\SingleDayEvent;
@@ -146,36 +147,35 @@
146147
});
147148

148149
it('queries occurrences based on timezone', function () {
149-
$utcDate = now('UTC')->setTimeFromTimeString('11:00')->toImmutable();
150-
$laDate = now('America/Los_Angeles')->setTimeFromTimeString('11:00')->toImmutable();
150+
$utcDate = Date::parse('2026-03-26 11am')->toImmutable();
151+
$laDate = $utcDate->shiftTimezone('America/Los_Angeles');
151152

152153
$entry = makeEvent([
153-
'start_date' => $utcDate->toDateString(),
154+
'start_date' => '2026-03-26',
154155
'timezone' => 'America/Los_Angeles',
155-
'start_time' => '22:00',
156+
'start_time' => '05:00',
156157
'end_time' => '23:00',
157158
]);
158159

159160
$events1 = EventFactory::createFromEntry($entry)->occurrencesBetween($utcDate->startOfDay(), $utcDate->endOfDay());
160161
$events2 = EventFactory::createFromEntry($entry)->occurrencesBetween($laDate->startOfDay(), $laDate->endOfDay());
161162

162-
expect($events1)->toHaveCount(0);
163+
expect($events1)->toHaveCount(1);
163164
expect($events2)->toHaveCount(1);
164165
});
165166

166-
it('retrieves occurrences that span days', function () {
167-
$date = CarbonImmutable::createFromDate(2026, 2, 28);
167+
it('retrieves occurrences that span days in different timezone than event', function ($from, $to, $count) {
168168
$entry = Entry::make()
169169
->collection('events')
170170
->data([
171-
'start_date' => $date->toDateString(),
171+
'start_date' => now()->toDateString(),
172172
'timezone' => 'America/Los_Angeles',
173173
'start_time' => '05:00',
174174
'end_time' => '23:00',
175175
]);
176176

177-
$events1 = EventFactory::createFromEntry($entry)->occurrencesBetween($date->startOfMonth(), $date->endOfMonth());
178-
// $events2 = EventFactory::createFromEntry($entry)->occurrencesBetween($date->startOfMonth(), $date->endOfMonth()->endOfWeek());
179-
180-
expect($events1)->toHaveCount(1);
181-
})->skip();
177+
expect(EventFactory::createFromEntry($entry))->occurrencesBetween($from, $to)->toHaveCount($count);
178+
})->with([
179+
[now()->startOfDay(), now()->endOfDay()->addDay(), 1],
180+
[now()->startOfDay(), now()->endOfDay(), 1],
181+
]);

0 commit comments

Comments
 (0)