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.

28 lines • 1.31 kB
import { Temporal } from "../../internal/temporal.js"; /** * Return the start of the specified date `unit` for a given ISO 8601 date string. * * - `"day"` returns the date itself: a date is already a whole day, as `endOfDate` treats it. * - `unit` accepts the singular or plural name (`"month"` or `"months"`), as Temporal does. * - Returns "" for invalid inputs. * * @param value ISO 8601 date string * @param unit date unit, singular or plural, to specify the unit for the start * @param optionsArg How the week is defined * @returns ISO 8601 string representing the start of the specified unit, or "" on invalid input * * @example startOfDate("2024-02-29", "month") // "2024-02-01" * @example startOfDate("2024-02-29", "day") // "2024-02-29" * @example startOfDate("2024-02-29", "months") // "2024-02-01" * @example startOfDate("invalid-date", "month") // "" */ export declare function startOfDate(value: string, unit: Temporal.SmallestUnit<Temporal.DateUnit>, optionsArg?: { /** * The first day of the week, which sets where a `"week"` unit starts. `"monday"` is the ISO * 8601 week, Monday to Sunday; `"sunday"` runs Sunday to Saturday. Any other value returns * `""`, whatever the unit. * * @defaultValue `"monday"` */ weekStartsOn?: "monday" | "sunday"; }): string;