@@ -233,6 +233,44 @@ public function assemble(): void
233233 );
234234 }
235235
236+ /**
237+ * Shift the weekday if the entry starts on an earlier or later weekday in the display timezone
238+ *
239+ * @param int $day
240+ * @param int $shift
241+ *
242+ * @return int
243+ */
244+ protected function shiftDay (int $ day , int $ shift ): int
245+ {
246+ return ((($ day - 1 + $ shift ) % 7 ) + 7 ) % 7 + 1 ;
247+ }
248+
249+
250+
251+ /**
252+ * Shift the whole weekdays array if the entries start on an earlier or later weekday in the display timezone
253+ *
254+ * @param array $days
255+ * @param int $shift
256+ *
257+ * @return array
258+ */
259+ protected function shiftDays (array $ days , int $ shift ): array
260+ {
261+ if ($ shift === 0 ) {
262+ return $ days ;
263+ }
264+
265+ $ out = [];
266+ foreach ($ days as $ d ) {
267+ $ out [] = $ this ->shiftDay ($ d , $ shift );
268+ }
269+ sort ($ out );
270+
271+ return $ out ;
272+ }
273+
236274 /**
237275 * Generate and save the part of the entry flyout, that remains equal for all entries of the rotation
238276 *
@@ -265,11 +303,14 @@ protected function generateAndSetRotationInfo(): static
265303 };
266304 $ timeFormatter = new \IntlDateFormatter (\Locale::getDefault (), $ noneType , $ shortType , $ displayTimezone );
267305 $ dateFormatter = new \IntlDateFormatter (\Locale::getDefault (), $ shortType , $ noneType , $ displayTimezone );
268- $ firstHandoff = $ dateFormatter ->format (DateTime::createFromFormat (
269- 'Y-m-d H:i ' ,
270- $ this ->firstHandoff . ' ' . $ time ,
271- $ scheduleTimezone
272- ));
306+
307+ $ firstHandoffDt = DateTime::createFromFormat ('Y-m-d H:i ' , $ this ->firstHandoff . ' ' . $ time , $ scheduleTimezone );
308+ $ scheduleDt = (clone $ firstHandoffDt )->setTime (0 , 0 );
309+ $ displayDt = (clone $ firstHandoffDt )->setTimezone ($ displayTimezone )->setTime (0 , 0 );
310+
311+ $ shift = $ displayDt <=> $ scheduleDt ;
312+
313+ $ firstHandoff = $ dateFormatter ->format ($ firstHandoffDt );
273314
274315 if (($ this ->rotationOptions ['frequency ' ] ?? null ) === 'd ' ) {
275316 $ handoff = sprintf (
@@ -318,7 +359,7 @@ protected function generateAndSetRotationInfo(): static
318359 );
319360
320361 if ($ this ->mode === "partial " ) {
321- $ days = $ this ->rotationOptions ["days " ];
362+ $ days = $ this ->shiftDays ( $ this -> rotationOptions ["days " ], $ shift ) ;
322363 $ from = $ timeFormatter ->format (DateTime::createFromFormat (
323364 'H:i ' ,
324365 $ this ->rotationOptions ["from " ],
@@ -356,13 +397,13 @@ protected function generateAndSetRotationInfo(): static
356397 )
357398 )->addHtml ($ firstHandoffInfo );
358399 } elseif ($ this ->mode === "multi " ) {
359- $ fromDay = $ weekdayNames [$ this ->rotationOptions ["from_day " ]];
400+ $ fromDay = $ weekdayNames [$ this ->shiftDay ( $ this -> rotationOptions ["from_day " ], $ shift ) ];
360401 $ fromAt = $ timeFormatter ->format (DateTime::createFromFormat (
361402 'H:i ' ,
362403 $ this ->rotationOptions ["from_at " ],
363404 $ scheduleTimezone
364405 ));
365- $ toDay = $ weekdayNames [$ this ->rotationOptions ["to_day " ]];
406+ $ toDay = $ weekdayNames [$ this ->shiftDay ( $ this -> rotationOptions ["to_day " ], $ shift ) ];
366407 $ toAt = $ timeFormatter ->format (DateTime::createFromFormat (
367408 'H:i ' ,
368409 $ this ->rotationOptions ["to_at " ],
0 commit comments