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.

46 lines • 2.78 kB
import { UnixUnit } from "../validate/isValidUnixUnit.js"; /** * Return the start of the quarter for a Unix timestamp. * * - Converts to ZonedDateTime, calculates quarter start, converts back to epoch. * - Q1 returns month 1, Q2 returns month 4, Q3 returns month 7, Q4 returns month 10, with every field below the day reset — milliseconds included. * - Returns the real start of the local quarter in `timeZone` (see `floorToZone`), so the result is never after `value`. * - Takes no `disambiguation` or `offset`: a boundary is always a real instant, as TC39's `startOfDay()` * takes neither. Those ignored options were removed in 1.16.0. * - Returns null for invalid input. * - `value` is a safe integer or a digit string (`"1706659200000"`); anything else returns null. * - **Limit at an offset with seconds.** The instant is placed in the offset's whole-minute zone, * moved by its seconds, and the moved instant must be inside Temporal's range. So within the * offset's seconds (under a minute) of the last instant Temporal supports * (`+275760-09-13T00:00:00Z`) for an offset east of UTC, or of the first * (`-271821-04-20T00:00:00Z`) for one west, this returns `null`. An offset to the minute has no * such limit. * * @param value Unix epoch: a safe integer, or a string of optionally negative ASCII digits * @param options optional: how `value` is read and the zone the quarter is found in * @returns Unix epoch number representing the start of the quarter, or null on invalid input * * @example startOfQuarterForUnix(1706659200000, { timeZone: "UTC" }) // 1704067200000 * @example startOfQuarterForUnix(1715776496789, { timeZone: "UTC" }) // 1711929600000 (2024-05-15T12:34:56.789Z; the milliseconds are reset too) * @example startOfQuarterForUnix(-86400000, { timeZone: "UTC" }) // -7948800000 (1969-12-31 is in Q4, which starts Oct 1) * @example startOfQuarterForUnix(276046200000, { timeZone: "Africa/Tunis" }) // 276040800000 (the first pass of Q4 1978's repeated first hour) * @example startOfQuarterForUnix(NaN) // null */ export declare function startOfQuarterForUnix(value: number | string, options?: { /** * The unit the epoch values are counted in: `"seconds"` or `"milliseconds"`, singular or * plural. Any other value returns `null`. The result is in the same unit. * * @defaultValue `"milliseconds"` */ epochUnit?: UnixUnit; /** * The time zone the unit boundaries are found in: an IANA name, a UTC offset (a time zone * identifier such as `+05:30`, `+0530` or `-08`, or a stored offset `±HH:MM[:SS]`, what * `getTimeZoneOffset` returns), or `"local"` for the system time zone. An unknown zone returns * `null`. * * @defaultValue `"UTC"` */ timeZone?: string; }): number | null;