File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
resources/js/packages/ui/src/utils Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -149,13 +149,18 @@ export function getLocalizedDayJs(timestamp?: string | null) {
149149
150150/**
151151 * Create a dayjs instance for a specific wall-clock time on a given day.
152- * Sets hour/minute directly to avoid DST issues with .add() on transition days.
152+ * Sets hour/minute directly to avoid DST issues with .add(minutes) on
153+ * transition days. Negative or overflow values are normalised by shifting
154+ * whole days (`.add(n, 'day')` is DST-safe).
153155 */
154156export function getLocalizedDayJsFromMinutes ( dayStr : string , minutesFromMidnight : number ) {
157+ const dayOffset = Math . floor ( minutesFromMidnight / ( 24 * 60 ) ) ;
158+ const remainder = minutesFromMidnight - dayOffset * 24 * 60 ;
155159 return dayjs
156160 . tz ( `${ dayStr } T00:00:00` , getUserTimezone ( ) )
157- . hour ( Math . floor ( minutesFromMidnight / 60 ) )
158- . minute ( Math . round ( minutesFromMidnight % 60 ) )
161+ . add ( dayOffset , 'day' )
162+ . hour ( Math . floor ( remainder / 60 ) )
163+ . minute ( Math . round ( remainder % 60 ) )
159164 . second ( 0 ) ;
160165}
161166
You can’t perform that action at this time.
0 commit comments