UNPKG

date-vir

Version:

Easy and explicit dates and times.

96 lines (95 loc) 2.58 kB
import { type DurationBySelection, type DurationUnitSelection, type RoundOptions } from '@date-vir/duration'; import { FullDate } from '../full-date/full-date-shape.js'; /** * Diffs two dates and returns the diff in the specified unit or units. When a multiple units are * provided with the `units` input property, an array is returned with the full diff duration * contained in each entry in the requested unit. * * Note: when years, quarters, or months are used for the unit, "long term" durations are used to * calculate the diff. See more details here: * https://moment.github.io/luxon/#/math?id=casual-vs-longterm-conversion-accuracy * * @category Calculation * @example * * ```ts * import {diffDates, DurationUnit} from 'date-vir'; * * const exampleDate: FullDate = { * year: 2024, * month: 1, * day: 5, * hour: 1, * minute: 1, * second: 1, * millisecond: 1, * timezone: 'UTC', * }; * * // get the diff in days * diffDates({start: exampleDate, end: {...exampleDate, day: 6}}, {days: true}); // {days: 1} * // get the full diff separately in days and also years * diffDates( * { * start: exampleDate, * end: { * ...exampleDate, * day: exampleDate.day + 1, * hour: exampleDate.hour + 3, * }, * }, * { * days: true, * hours: true, * }, * ); * // {days: 1, hours: 3} * ``` */ export declare function diffDates<const SelectedUnits extends Readonly<DurationUnitSelection>>({ start, end, }: Readonly<{ start: Readonly<FullDate>; end: Readonly<FullDate>; }>, /** Which units the output should contain. */ units: SelectedUnits, options?: Readonly<RoundOptions>): DurationBySelection<SelectedUnits>; /** * Checks if `fullDate` is after `relativeTo`. * * @category Calculation * @example * * ```ts * import {isDateAfter, type FullDate} from 'date-vir'; * * const exampleDate: FullDate = { * year: 2024, * month: 1, * day: 5, * hour: 1, * minute: 1, * second: 1, * millisecond: 1, * timezone: 'UTC', * }; * * isDateAfter({ * fullDate: exampleDate, * relativeTo: { * ...exampleDate, * year: 1900, * }, * }); // `true` * * isDateAfter({ * fullDate: exampleDate, * relativeTo: { * ...exampleDate, * year: 3000, * }, * }); // `false` * ``` */ export declare function isDateAfter({ relativeTo, fullDate, }: { relativeTo: Readonly<FullDate>; fullDate: Readonly<FullDate>; }): boolean;