File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -44,6 +44,8 @@ class Events
4444
4545 private array $ terms = [];
4646
47+ private ?string $ timezone = null ;
48+
4749 public static function defaultTimezone (): string
4850 {
4951 return static ::setting ('timezone ' , config ('statamic.system.display_timezone ' ) ?? config ('app.timezone ' , 'UTC ' ));
@@ -139,6 +141,13 @@ public function terms(string|array $terms): self
139141 return $ this ;
140142 }
141143
144+ public function timezone (string $ timezone ): self
145+ {
146+ $ this ->timezone = $ timezone ;
147+
148+ return $ this ;
149+ }
150+
142151 public function between (string |CarbonInterface $ from , string |CarbonInterface $ to ): EntryCollection |LengthAwarePaginator
143152 {
144153 return $ this ->output (
@@ -157,6 +166,13 @@ private function output(callable $type): EntryCollection|LengthAwarePaginator
157166 {
158167 $ occurrences = $ this ->entries ()->occurrences (generator: $ type );
159168
169+ if (! is_null ($ this ->timezone )) {
170+ $ occurrences ->transform (fn (Entry $ occurrence ) => $ occurrence
171+ ->setSupplement ('start ' , $ occurrence ->start ->setTimezone ($ this ->timezone ))
172+ ->setSupplement ('end ' , $ occurrence ->end ->setTimezone ($ this ->timezone ))
173+ );
174+ }
175+
160176 if ($ this ->offset ) {
161177 $ occurrences = $ occurrences ->slice (offset: $ this ->offset );
162178 }
Original file line number Diff line number Diff line change @@ -193,6 +193,9 @@ private function generator(): Generator
193193 )->when (
194194 value: $ this ->params ->bool ('collapse_multi_days ' ),
195195 callback: fn (Generator $ generator ) => $ generator ->collapseMultiDays ()
196+ )->when (
197+ value: $ this ->params ->get ('timezone ' ),
198+ callback: fn (Generator $ generator , string $ tz ) => $ generator ->timezone (timezone: $ tz )
196199 );
197200 }
198201
Original file line number Diff line number Diff line change 88use Statamic \Facades \Site as SiteFacade ;
99use Statamic \Sites \Site ;
1010use Statamic \Support \Arr ;
11- use TransformStudios \Events \Tags \Events ;
11+ use TransformStudios \Events \Tags \Events as EventsTag ;
1212
1313beforeEach (function () {
1414 Entry::make ()
2424 'categories ' => ['one ' ],
2525 ])->save ();
2626
27- $ this ->tag = app (Events ::class);
27+ $ this ->tag = app (EventsTag ::class);
2828});
2929
3030test ('can generate between occurrences ' , function () {
409409 'long ' => 'Sunday ' ,
410410 ]);
411411});
412+
413+ test ('uses the timezone param when generating occurrences ' , function () {
414+ Carbon::setTestNow (now ()->setTimeFromTimeString ('10:00 ' ));
415+
416+ $ this ->tag
417+ ->setContext ([])
418+ ->setParameters ([
419+ 'collection ' => 'events ' ,
420+ 'from ' => Carbon::now ()->subDay (),
421+ 'timezone ' => 'America/Vancouver ' ,
422+ 'to ' => Carbon::now ()->addDays (2 ),
423+ ]);
424+
425+ $ occurrences = $ this ->tag ->between ();
426+
427+ expect ($ occurrences )->toHaveCount (1 )
428+ ->first ()->start ->timezone ->getName ()->toBe ('America/Vancouver ' );
429+ });
You can’t perform that action at this time.
0 commit comments