/** YYYY */ export type YearKey = `${number}`; /** YYYY-MM */ export type MonthKey = `${number}-${number}`; /** YYYY-MM-DD */ export type DateKey = `${MonthKey}-${number}`; /** YYYY-MM--W (0-3, aligned to month) */ export type WeekKey = `${MonthKey}--${number}`; /** * Represents a day in the Gregorian calendar in the form of [year, month, day]. * Note that `month` is one-based, not zero-based. As opposed to JS Date's `monthIndex`. * * I prefer working with Day objects instead of Date objects to avoid all kind of problems 😁 */ export declare class Day { static readonly LOWEST: Day; static readonly HIGHEST: Day; readonly year: number; readonly month: number; readonly day: number; constructor(year: number, month: number, day: number); /** Creates a Day from a JS Date object */ static fromDate(date: Date): Day; /** Creates a Day from a time key. If month or day is not provided, it will default to the earliest that matches */ static fromKey(key: DateKey | WeekKey | MonthKey | YearKey): Day; /** Creates a Day from a binary number generated by `toBinary` */ static fromBinary(binary: number): Day; /** Converts the day into a JS Date object */ toDate(): Date; /** Converts the day into a binary number */ toBinary(): number; /** Returns the UTC timestamp for this day */ toTimestamp(): number; get yearKey(): YearKey; get monthKey(): MonthKey; get weekKey(): WeekKey; get dateKey(): DateKey; /** Returns a new Day instance for `days` days into the future */ nextDays(days: number): Day; /** Returns a new Day instance for the following day */ nextDay(): Day; /** Equal */ static eq(a: Day, b: Day): boolean; /** Less than */ static lt(a: Day, b: Day): boolean; /** Greater than */ static gt(a: Day, b: Day): boolean; /** Min between two days (past) */ static min(a: Day, b: Day): Day; /** Max between two days (future) */ static max(a: Day, b: Day): Day; /** Clamp day between two days */ static clamp(day: Day, a: Day, b: Day): Day; } export interface TimeKeysResult { dateKeys: DateKey[]; weekKeys: WeekKey[]; monthKeys: MonthKey[]; yearKeys: YearKey[]; dateToWeekIndex: number[]; dateToMonthIndex: number[]; dateToYearIndex: number[]; } /** * Generates each time key contained in an interval of time [start, end]. * Also generates indexes to map between date keys and the rest. */ export declare const genTimeKeys: (start: Day, end: Day) => TimeKeysResult; /** * Available human-readable formats * * Examples for day="2020-12-25", seconds=12345: * - y: 2020 * - ym: December 2020 * - ymd: December 25, 2020 * - symd: 12/25/2020 * - ymdh: December 25, 2020, 03 AM * - ymdhm: December 25, 2020, 03:25 AM * - ymdhms: December 25, 2020, 03:25:45 AM */ export type TimeFormat = "y" | "ym" | "ymd" | "symd" | "ymdh" | "ymdhm" | "ymdhms"; /** Format a Day (+seconds) into a human-readable string */ export declare const formatTime: (format: TimeFormat, day: Day, secondsOfDay?: number) => string; /** Point in time */ export interface Datetime { key: DateKey | WeekKey | MonthKey | YearKey; secondOfDay?: number; } /** Format a Datetime into a human-readable string. @see formatTime */ export declare const formatDatetime: (format: TimeFormat, datetime?: Datetime) => string; /** Finds the time difference in seconds between two Datetimes */ export declare const diffDatetime: (a: Datetime, b: Datetime) => number;