UNPKG

@northguild/gmt

Version:

Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.

34 lines (32 loc) • 1.33 kB
import { Temporal } from "../../internal/temporal.js"; import { nowInstant } from "../../internal/temporalCompat/clock.js"; import { zonedDateTimeOf } from "../../internal/zonedWallClock.js"; // src/zoned/compare/isZonedFuture.ts /** * Return true when `value` represents an instant strictly after now. * * - Unlike the plain `isFuture`, which compares calendar days, this compares * the exact instant `value` represents against `nowInstant()` — * `value` carries a full time-of-day, not just a date. * - `value === now` (to the precision available) returns false — "future" * means strictly after, not on-or-after. * - Returns false if `value` is invalid. * * @param value ISO ZonedDateTime string * @returns true if `value` is after the current instant, false on invalid input * * @example isZonedFuture("2999-01-01T00:00:00Z[UTC]") // true (an instant in the distant future) * @example isZonedFuture("2020-01-01T00:00:00Z[UTC]") // false (an instant in the distant past) * @example isZonedFuture("invalid") // false */ function isZonedFuture(value) { const zonedDateTime = zonedDateTimeOf(value); if (zonedDateTime === null) return false; try { const instant = zonedDateTime.toInstant(); return Temporal.Instant.compare(instant, nowInstant()) === 1; } catch { return false; } } export { isZonedFuture };