Similar to Incrementing a date in JavaScript but I am looking for the number of milliseconds to the next day given a timezone.
This is so that I can trigger a subscription or React state change when the local time reaches midnight.
The function signature would be
function millisecondsBeforeNextDay(now: number| Date, timeZone: string) : number {
}
and used like
export function useDayClockState(): Date {
const defaultCalendar = Localization.getCalendars()[0];
const now = useClockState(24 * 60 * 60 * 1000, millisecondsBeforeNextDay(Date.now(), defaultCalendar.timeZone!));
return now;
}
It needs one caveat though, it should not return 24 hours. But 0
if the current instant is midnight.