@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.
27 lines • 1.93 kB
TypeScript
import { Temporal } from "./temporal.js";
/**
* One field of a zoned "now" as the `get*NowUnit` accessors return it: zero-padded to two digits
* (three for sub-second fields), the day of week unpadded, and the year as Temporal writes one
* (`isoYearString`: four digits, or a sign and six outside 0000–9999). The week number is the
* caller's, since the plain and zoned accessors read it through `parseWeekFromDate` and the utc and
* unix ones from the ISO date.
*
* @param now the current moment on the wall clock being read: a zoned date-time, or the plain wall
* clock of a stored UTC offset with seconds, which no time zone identifier can carry
* @param unit a singular unit, `dayOfWeek` included (already validated by the caller)
* @param week the week number for `now`, as a string
* @returns the field, or "" for any other unit
* @example zonedNowUnitValue(Temporal.ZonedDateTime.from("2024-03-05T07:08:09.012+00:00[UTC]"), "millisecond", () => "10") // "012"
* @example zonedNowUnitValue(Temporal.ZonedDateTime.from("2024-03-05T07:08:09+00:00[UTC]"), "week", () => "10") // "10"
* @example zonedNowUnitValue(Temporal.ZonedDateTime.from("2024-03-05T07:08:09+00:00[UTC]"), "quarter", () => "10") // ""
*/
export declare function zonedNowUnitValue<Clock extends Temporal.ZonedDateTime | Temporal.PlainDateTime>(now: Clock, unit: string | null | undefined, week: (now: Clock) => string): string;
/**
* The ISO 8601 week number of `now`'s date, the week the utc and unix `get*NowUnit` accessors read.
*
* @param now the current moment on the wall clock being read: a zoned date-time, or the plain wall
* clock of a stored UTC offset with seconds, which no time zone identifier can carry
* @returns the week number as a string
* @example isoWeekOfYear(Temporal.ZonedDateTime.from("2024-12-30T00:00:00+00:00[UTC]")) // "1"
*/
export declare function isoWeekOfYear(now: Temporal.ZonedDateTime): string;