@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.
64 lines • 3.04 kB
TypeScript
import { Temporal } from "./temporal.js";
/** The cores of the plain start-of, equality and week-start functions, so none calls another. */
/**
* The first day of the `unit` a date falls in.
*
* - `week` starts on Monday or Sunday, as `weekStartsOn` says.
* - May throw at the edge of the Temporal range; each caller turns that into its sentinel.
*
* @param date the date
* @param unit `"year"`, `"month"`, `"week"` or `"day"`
* @param weekStartsOn the first day of the week
* @returns the start of the unit as a `PlainDate`
*
* @example startOfPlainDate(Temporal.PlainDate.from("2024-03-15"), "month", "monday").toString() // "2024-03-01"
*/
export declare function startOfPlainDate(date: Temporal.PlainDate, unit: Temporal.DateUnit, weekStartsOn: "monday" | "sunday"): Temporal.PlainDate;
/**
* The start of the `unit` a date-time falls in, with every finer field reset to zero.
*
* May throw at the edge of the Temporal range; each caller turns that into its sentinel.
*
* @param dateTime the date-time
* @param unit any date or time unit
* @param weekStartsOn the first day of the week
* @returns the start of the unit as a `PlainDateTime`
*
* @example startOfPlainDateTime(Temporal.PlainDateTime.from("2024-03-15T10:30"), "hour", "monday").toString() // "2024-03-15T10:00:00"
*/
export declare function startOfPlainDateTime(dateTime: Temporal.PlainDateTime, unit: Temporal.DateTimeUnit, weekStartsOn: "monday" | "sunday"): Temporal.PlainDateTime;
/**
* Whether two strict ISO dates or date-times name the same calendar day.
*
* @param value1 the first candidate
* @param value2 the second candidate
* @returns `true` when both are valid and share year, month and day; `false` otherwise
*
* @example sameIsoDateLike("2024-03-15", "2024-03-15T10:00") // true
* @example sameIsoDateLike("2024-03-15", "2024-03-16") // false
*/
export declare function sameIsoDateLike(value1: unknown, value2: unknown): boolean;
/**
* The first day of the week a date falls in, for a locale's first day of the week.
*
* @param date the date
* @param firstDay the locale's first day, 1 (Monday) to 7 (Sunday)
* @returns the first day of that week
*
* @example localeStartOfWeek(Temporal.PlainDate.from("2024-03-13"), 7).toString() // "2024-03-10"
*/
export declare function localeStartOfWeek(date: Temporal.PlainDate, firstDay: number): Temporal.PlainDate;
/**
* Whether two dates fall in the same `unit`.
*
* May throw at the edge of the Temporal range; each caller turns that into `false`.
*
* @param date1 the first date
* @param date2 the second date
* @param unit `"year"`, `"month"`, `"week"` or `"day"`
* @param weekStartsOn the first day of the week
* @returns whether both dates share the start of the unit
*
* @example sameDateBy(Temporal.PlainDate.from("2024-03-01"), Temporal.PlainDate.from("2024-03-31"), "month", "monday") // true
*/
export declare function sameDateBy(date1: Temporal.PlainDate, date2: Temporal.PlainDate, unit: Temporal.DateUnit, weekStartsOn: "monday" | "sunday"): boolean;