Skip to content

Commit 71c8992

Browse files
committed
Fix getLocalizedDayJsFromMinutes handling negative minute values
1 parent 53d91b6 commit 71c8992

File tree

1 file changed

+8
-3
lines changed
  • resources/js/packages/ui/src/utils

1 file changed

+8
-3
lines changed

resources/js/packages/ui/src/utils/time.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff 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
*/
154156
export 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

0 commit comments

Comments
 (0)