UNPKG

@thi.ng/date

Version:

Datetime types, relative dates, math, iterators, composable formatters, locales

172 lines 4.15 kB
import type { Fn, Fn2 } from "@thi.ng/api"; import type { DateTime } from "./datetime.js"; /** * Days per month LUT (non-leap year) */ export declare const DAYS_IN_MONTH: number[]; /** * LUT of day-in-year values for 1st of each month (non-leap year) */ export declare const DAYS_IN_MONTH_OFFSET: number[]; /** * There're 97 leap years and 303 normal years per 400 years */ export declare const DAYS_IN_400YEARS: number; /** * Second duration in milliseconds */ export declare const SECOND = 1000; /** * Minute duration in milliseconds */ export declare const MINUTE: number; /** * Hour duration in milliseconds */ export declare const HOUR: number; /** * Day duration in milliseconds */ export declare const DAY: number; /** * Week duration in milliseconds */ export declare const WEEK: number; /** * Mean year duration (365.2425 days) in milliseconds */ export declare const YEAR: number; /** * Mean month duration (30.436875 days) in milliseconds */ export declare const MONTH: number; export interface Locale { /** * Names of months */ months: string[]; /** * Names of weekdays (starting w/ Sunday) */ days: string[]; /** * Default date format spec for use with {@link defFormat} * * @defaultValue ["E", "/ED", "d", "/DM", "MMM", "/MY", "yyyy"] */ date: string[]; /** * Default time format spec for use with {@link defFormat} * * @defaultValue ["H", "/HM", "mm"] */ time: string[]; /** * Default combined date & time format spec for use with {@link defFormat} * and {@link DateTime.toLocaleString}. * * @defaultValue concatenation of `date` and `time` options */ dateTime: string[]; /** * Separator between day & month. * * @defaultValue "/" */ sepDM: string; /** * Separator between month & year * * @defaultValue " " */ sepMY: string; /** * Separator between weekday & day * * @defaultValue " " */ sepED: string; /** * Separator between hour & minute * * @defaultValue ":" */ sepHM: string; /** * Singular & plural versions of various date/time units. */ units: Record<Precision, LocaleUnit>; /** * Translated version of "less than" for use with {@link unitsLessThan}. * (`%s` will be replaced with the provided numeric value). */ less: string; /** * Template for past tense (`%s` will be replaced with result). */ past: string; /** * Translated version of "now". */ now: string; /** * Template for future tense (`%s` will be replaced with result). */ future: string; } export interface LocaleUnit { /** * Singular */ s: string; /** * Plural */ p: string; /** * Singular dativ. If omitted, the same as singular. */ sd?: string; /** * Plural dativ. If omitted, the same as plural. */ pd?: string; } /** * A partially optional version of {@link Locale}, for use with * {@link setLocale}. */ export type LocaleSpec = Pick<Locale, "months" | "days"> & Partial<Omit<Locale, "months" | "days">>; export interface IEpoch { getTime(): number; } export interface EpochIteratorConstructor { ([from, to]: MaybeDate[]): EpochIterator; (from: MaybeDate, to: MaybeDate): EpochIterator; } export type EpochIterator = IterableIterator<number>; /** * DateTime precision/resolution IDs: * * - y : year * - M : month * - d : day * - h : hour * - m : minute * - s : second * - t : millisecond */ export type Precision = "y" | "M" | "d" | "h" | "m" | "s" | "t"; export type Period = Precision | "w" | "q"; /** * Object which maps {@link Period} IDs to their respective values (in * milliseconds). */ export declare const PERIODS: Record<Period, number>; export type FormatFn = Fn2<Date, boolean, string>; export type MaybeDate = DateTime | Date | number | string; /** * Date rounding function for {@link MaybeDate} inputs. */ export type RoundingFn = Fn<MaybeDate, number>; //# sourceMappingURL=api.d.ts.map