@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.
61 lines • 3.31 kB
TypeScript
import { Temporal } from "./temporal.js";
/**
* Return the start of the specified date `unit` for a `Temporal.PlainDate`.
*
* - Always uses Monday as the week start (consistent with roundDate semantics).
* - Works in `source`'s own calendar (a Hebrew month starts on its day 1).
* - Does NOT validate the unit — caller ensures it is a DateUnit.
*
* @param source Temporal.PlainDate to round
* @param unit DateUnit to specify the unit for the start
* @returns Temporal.PlainDate at the start of the specified unit; throws RangeError when it lies
* before the representable range
*/
export declare function getStartOfDateUnit(source: Temporal.PlainDate, unit: string): Temporal.PlainDate;
/**
* Add `amount` units of the specified date `unit` to a `Temporal.PlainDate`.
*
* - Calendar units resolve in `source`'s calendar through the Temporal compat layer.
* - Does NOT validate the unit — caller ensures it is a DateUnit.
*
* @param date Temporal.PlainDate to advance
* @param unit DateUnit to add
* @param amount number of units to add
* @returns new Temporal.PlainDate advanced by the specified amount
*/
export declare function addDateUnit(date: Temporal.PlainDate, unit: string, amount: number): Temporal.PlainDate;
/**
* Return the start of the date `unit` after the one containing `source`.
*
* - Steps one unit first and truncates after, so `source`'s own start is never materialised: the
* month holding the first representable date (`-271821-04-19`) began before the range, while the
* next month's start did not. Both orders agree everywhere else, because a one-unit step clamps
* within the next unit (Jan 31 + 1 month = Feb 29, whose month starts on Feb 1).
* - Always uses Monday as the week start, like `getStartOfDateUnit`.
* - Does NOT validate the unit — caller ensures it is a DateUnit.
*
* @param source Temporal.PlainDate inside the current unit
* @param unit DateUnit to step by
* @returns Temporal.PlainDate at the start of the next unit
*
* @example getStartOfNextDateUnit(Temporal.PlainDate.from("2024-01-31"), "month") // 2024-02-01
* @example getStartOfNextDateUnit(Temporal.PlainDate.from("-271821-04-19"), "month") // -271821-05-01
*/
export declare function getStartOfNextDateUnit(source: Temporal.PlainDate, unit: string): Temporal.PlainDate;
/**
* Return the whole days from the start of the date `unit` containing `source` to `source`.
*
* - Read from the calendar fields, so the unit's start is never materialised (it may lie before
* the representable range).
* - Always uses Monday as the week start, like `getStartOfDateUnit`. A day unit is 0 days in.
* - Accepts a `Temporal.PlainDate` or a `Temporal.PlainDateTime` (only its date matters).
* - Does NOT validate the unit — caller ensures it is a DateUnit.
*
* @param source value with calendar date fields, read in its own calendar
* @param unit DateUnit to measure within
* @returns number of whole days since the unit started
*
* @example getDaysIntoDateUnit(Temporal.PlainDate.from("2024-03-13"), "month") // 12
* @example getDaysIntoDateUnit(Temporal.PlainDate.from("2024-03-13"), "week") // 2 (a Wednesday)
*/
export declare function getDaysIntoDateUnit(source: Pick<Temporal.PlainDate, "day" | "dayOfWeek" | "dayOfYear">, unit: string): number;