Skip to content

startOrEndOfUnix

startOrEndOfUnix(value: number, unit: any, options: { epochUnit?: "seconds" | "milliseconds"; timeZone?: string; weekStartsOn?: "monday" | "sunday"; disambiguation?: Disambiguation; offset?: Offset; }, isEnd: boolean): number
import { startOrEndOfUnix } from "@northguild/gmt/unix/calculate";

Internal shared implementation for startOfUnix / endOfUnix.

  • Converts the epoch to a ZonedDateTime, snaps to the start or end of the requested unit, then converts back to an epoch number.
  • Supports every Temporal DateUnit and TimeUnit.
  • epochUnit controls whether the input/output is interpreted as "milliseconds" (default) or "seconds".
  • timeZone defaults to the system time zone via getSystemTimeZone().
  • disambiguation and offset are forwarded to Temporal’s .with() for DST-gap/overlap boundaries; see startOfUnix’s JSDoc for the full semantics — they behave identically here.
Parameter Type Description
value number Unix epoch number
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
epochUnit? "seconds" | "milliseconds"
timeZone? string
weekStartsOn? "monday" | "sunday"
disambiguation? Disambiguation
offset? Offset

Unix epoch number, or null on invalid input

unix/calculate/startOrEndOfUnix.ts