@@ -233,6 +233,42 @@ 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+ * Shift the whole weekdays array if the entries start on an earlier or later weekday in the display timezone
251+ *
252+ * @param array $days
253+ * @param int $shift
254+ *
255+ * @return array
256+ */
257+ protected function shiftDays (array $ days , int $ shift ): array
258+ {
259+ if ($ shift === 0 ) {
260+ return $ days ;
261+ }
262+
263+ $ out = [];
264+ foreach ($ days as $ d ) {
265+ $ out [] = $ this ->shiftDay ($ d , $ shift );
266+ }
267+ sort ($ out );
268+
269+ return $ out ;
270+ }
271+
236272 /**
237273 * Generate and save the part of the entry flyout, that remains equal for all entries of the rotation
238274 *
@@ -265,11 +301,14 @@ protected function generateAndSetRotationInfo(): static
265301 };
266302 $ timeFormatter = new \IntlDateFormatter (\Locale::getDefault (), $ noneType , $ shortType , $ displayTimezone );
267303 $ 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- ));
304+
305+ $ firstHandoffDt = DateTime::createFromFormat ('Y-m-d H:i ' , $ this ->firstHandoff . ' ' . $ time , $ scheduleTimezone );
306+ $ scheduleDt = (clone $ firstHandoffDt )->setTime (0 , 0 );
307+ $ displayDt = (clone $ firstHandoffDt )->setTimezone ($ displayTimezone )->setTime (0 , 0 );
308+
309+ $ shift = $ displayDt <=> $ scheduleDt ;
310+
311+ $ firstHandoff = $ dateFormatter ->format ($ firstHandoffDt );
273312
274313 if (($ this ->rotationOptions ['frequency ' ] ?? null ) === 'd ' ) {
275314 $ handoff = sprintf (
@@ -318,7 +357,7 @@ protected function generateAndSetRotationInfo(): static
318357 );
319358
320359 if ($ this ->mode === "partial " ) {
321- $ days = $ this ->rotationOptions ["days " ];
360+ $ days = $ this ->shiftDays ( $ this -> rotationOptions ["days " ], $ shift ) ;
322361 $ from = $ timeFormatter ->format (DateTime::createFromFormat (
323362 'H:i ' ,
324363 $ this ->rotationOptions ["from " ],
@@ -356,13 +395,13 @@ protected function generateAndSetRotationInfo(): static
356395 )
357396 )->addHtml ($ firstHandoffInfo );
358397 } elseif ($ this ->mode === "multi " ) {
359- $ fromDay = $ weekdayNames [$ this ->rotationOptions ["from_day " ]];
398+ $ fromDay = $ weekdayNames [$ this ->shiftDay ( $ this -> rotationOptions ["from_day " ], $ shift ) ];
360399 $ fromAt = $ timeFormatter ->format (DateTime::createFromFormat (
361400 'H:i ' ,
362401 $ this ->rotationOptions ["from_at " ],
363402 $ scheduleTimezone
364403 ));
365- $ toDay = $ weekdayNames [$ this ->rotationOptions ["to_day " ]];
404+ $ toDay = $ weekdayNames [$ this ->shiftDay ( $ this -> rotationOptions ["to_day " ], $ shift ) ];
366405 $ toAt = $ timeFormatter ->format (DateTime::createFromFormat (
367406 'H:i ' ,
368407 $ this ->rotationOptions ["to_at " ],
0 commit comments