import type { MonthNumber } from "./constants.js"; import type { RequireAtLeastOne } from "./support/utility-types.js"; export type FormatPlainDateOptions = Omit; /** * Describes a basic plain-date object with minimal properties. * * @see {@link PlainDate} factory for creating objects */ export interface ComPlainDate { /** Year may be negative and up to 6 digits */ year: number; /** Month (1-12) */ month: MonthNumber; /** Day in month (1-31) */ day: number; /** `yyyy-mm-dd` (ISO 8601) */ iso: string; /** `yyyy-mm-dd` (ISO 8601) */ valueOf: () => this["iso"]; /** `yyyy-mm-dd` (ISO 8601) */ toString: () => this["iso"]; /** `yyyy-mm-dd` (ISO 8601) */ toJSON: () => this["iso"]; /** * Localize the date for display to a user. * * @param locale `Intl` {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument | locale }, defaults to system's locale if not given * @param options `Intl` {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat | format options }, defaults to "short" date-style if not given * * @example * ```ts * // "6/12/2023" * PlainDate({ year: 2023, month: 6, day: 12 }).toLocaleString('en'); * * // "6/12" * PlainDate({ year: 2023, month: 6, day: 12 }).toLocaleString('en', { month: 'numeric', day: 'numeric' }); * * // "June 12" * PlainDate({ year: 2023, month: 6, day: 12 }).toLocaleString('en', { month: 'long', day: 'numeric' }); * ``` */ toLocaleString: (locale?: Intl.LocalesArgument, options?: FormatPlainDateOptions) => string; /** * Get a native JS `Date` object in UTC. */ toUtcInstant: (time?: { hour?: number | string; minute?: number | string; second?: number | string; millisecond?: number | string; }) => Date; /** * Check for partial or complete equality. */ is: (x: RequireAtLeastOne<{ year?: number | string; month?: number | string; day?: number | string; }>) => boolean; constructor: PlainDateFactory; /** * Apply a pipeline of functions to this plain-date, from left to right. * * @param fns Functions that take a plain-date and return a plain-date * @returns The output of the last function */ pipe: (this: T, ...fns: Array<(date: T) => T>) => T; /** * Create a new plain-date object from this one, modified by a function. * * @param f A function that takes a plain-date and returns a date object with properties `year`, `month` & `day` * @returns A new plain-date made from the date */ map: (this: T, f: (x: T) => { year: number | string; month: number | string; day: number | string; }) => T; } /** * Describes a factory function that creates plain-date objects. * * Specific implementations of the factory may provide additional methods that * takes other kinds of arguments. */ export interface PlainDateFactory { (x: { year: number | string; month?: number | string; day?: number | string; }): T; fromString?: (this: PlainDateFactory, s: string) => T; fromUtcInstant?: (this: PlainDateFactory, instant?: Date) => T; fromLocalInstant?: (this: PlainDateFactory, instant?: Date) => T; fromInstant?: (this: PlainDateFactory, timezone: string, instant?: Date) => T; } /** * Factory function for making basic plain-date objects with minimal properties. * * @param date A date object with properties `year`, `month` & `day` * @returns A new immutable plain-date object */ export declare function PlainDate({ year, month, day }: { year: number | string; month?: number | string; day?: number | string; }): ComPlainDate; //# sourceMappingURL=PlainDate.d.ts.map