Skip to content

startOrEndOfUtc

startOrEndOfUtc(value: string, unit: any, options: { weekStartsOn?: "monday" | "sunday"; fractionalSecondDigits?: FractionalDigit; }, isEnd: boolean): string
import { startOrEndOfUtc } from "@northguild/gmt/utc/calculate";

Internal shared implementation for startOfUtc / endOfUtc.

  • Converts the UTC Instant to a ZonedDateTime, snaps to the start or end of the requested unit, then converts back to an Instant string.
  • Supports every Temporal DateUnit and TimeUnit.
  • weekStartsOn shifts the week boundary: "monday" (default) or "sunday".
  • fractionalSecondDigits overrides the default sub-second precision for the returned Instant string; defaults to 3 for millisecond, 6 for microsecond, 9 for nanosecond, and 0 for all coarser units.
Parameter Type Description
value string ISO UTC datetime string
unit any Temporal.DateUnit | Temporal.TimeUnit to snap to
isEnd boolean false for start-of-unit, true for end-of-unit

options

Option Type Default
weekStartsOn? "monday" | "sunday"
fractionalSecondDigits? FractionalDigit

UTC Instant string, or “” on invalid input

utc/calculate/startOrEndOfUtc.ts