diff --git a/src/Events.php b/src/Events.php index 60aa73f..5e19268 100644 --- a/src/Events.php +++ b/src/Events.php @@ -264,20 +264,21 @@ private function hasEnded(Entry $event, string|CarbonInterface $from): bool private function lastPossibleDate(Entry $event): ?CarbonImmutable { - $recurrence = $event->get('recurrence'); + // value() inherits from the origin so localized stubs still resolve dates + $recurrence = $event->value('recurrence'); - if ($recurrence === 'multi_day' || $event->get('multi_day')) { - $dates = collect($event->get('days'))->pluck('date')->filter(); + if ($recurrence === 'multi_day' || $event->value('multi_day')) { + $dates = collect($event->value('days'))->pluck('date')->filter(); return $dates->isEmpty() ? null : $this->parseDate($dates->max()); } if (in_array($recurrence, ['daily', 'weekly', 'monthly', 'every'])) { // no end date means it recurs forever - return $this->parseDate($event->get('end_date')); + return $this->parseDate($event->value('end_date')); } - return $this->parseDate($event->get('start_date')); + return $this->parseDate($event->value('start_date')); } // a date we can't read is one we can't rule out, so let it through to the generator @@ -306,7 +307,7 @@ private function hasStartDate(Entry $occurrence): bool } } - return $occurrence->has('start_date'); + return filled($occurrence->value('start_date')); } private function paginate(EntryCollection $occurrences): LengthAwarePaginator diff --git a/tests/LocalizedEventsTest.php b/tests/LocalizedEventsTest.php new file mode 100644 index 0000000..00d867b --- /dev/null +++ b/tests/LocalizedEventsTest.php @@ -0,0 +1,79 @@ + ['name' => 'English', 'locale' => 'en_US', 'url' => '/'], + 'ar' => ['name' => 'Arabic', 'locale' => 'ar', 'url' => '/ar/'], + ]); + + $this->collection->sites(['default', 'ar'])->save(); + + Carbon::setTestNow('2026-08-15 10:00:00'); +}); + +test('includes localized events that inherit start_date from the origin', function () { + $origin = Entry::make() + ->collection('events') + ->locale('default') + ->slug('art-collective') + ->data([ + 'title' => 'Collective Art Activities', + 'start_date' => '2026-08-31', + 'start_time' => '14:00', + 'end_time' => '16:00', + 'timezone' => 'America/Los_Angeles', + ]); + $origin->save(); + + $localized = $origin->makeLocalization('ar'); + $localized->set('title', 'أنشطة فنية جماعية'); + $localized->save(); + + expect($localized->has('start_date'))->toBeFalse() + ->and($localized->get('start_date'))->toBeNull() + ->and($localized->value('start_date'))->toBe('2026-08-31'); + + Site::setCurrent('ar'); + + $occurrences = Events::fromCollection('events') + ->site('ar') + ->between( + CarbonImmutable::parse('2026-08-01')->startOfDay(), + CarbonImmutable::parse('2026-08-31')->endOfDay() + ); + + expect($occurrences)->toHaveCount(1) + ->and($occurrences->first()->title)->toBe('أنشطة فنية جماعية') + ->and($occurrences->first()->start->toDateString())->toBe('2026-08-31'); +}); + +test('still drops localized events whose origin start date is in the past', function () { + $origin = Entry::make() + ->collection('events') + ->locale('default') + ->slug('past-event') + ->data([ + 'title' => 'Past Event', + 'start_date' => '2026-07-01', + 'start_time' => '14:00', + ]); + $origin->save(); + + $localized = $origin->makeLocalization('ar'); + $localized->set('title', 'حدث سابق'); + $localized->save(); + + Site::setCurrent('ar'); + + expect( + Events::fromCollection('events')->site('ar')->upcoming(1) + )->toBeEmpty(); +});