Skip to main content

Function: crossesViewerMidnight()

crossesViewerMidnight(dateISO, from, to, facilityTz, viewerTz): boolean

Defined in: src/lib/dates/tz.ts:202

Whether a facility-time fromto pair lands on two different calendar days in viewerTz.

A pair never crosses midnight in the facility's own zone (to > from is enforced by timePairSchema), but it routinely does in a distant viewer's: a 09:00–17:00 shift in America/New_York runs 9:00 PM → 5:00 AM the next day in Asia/Manila. Hours are always filed under the facility business day (ADR-0027); this is what lets the UI say so out loud instead of leaving the viewer to notice the mismatch against their own phone.

Parameters

dateISO

string

The facility business day the pair is filed under, as YYYY-MM-DD.

from

string

Pair start as 24-hour HH:MM, wall-clock in facilityTz.

to

string

Pair end as 24-hour HH:MM, wall-clock in facilityTz.

facilityTz

string

IANA timezone the wall times are expressed in (e.g. America/New_York).

viewerTz

string

IANA timezone to compare calendar days in (e.g. Asia/Manila).

Returns

boolean

true when start and end fall on different calendar days in viewerTz.

Throws

RangeError If either timezone is invalid or the date/time strings are unparseable.

Example

// A New York day shift spans two calendar days in Manila.
crossesViewerMidnight('2026-08-04', '09:00', '17:00', 'America/New_York', 'Asia/Manila'); // true