UNPKG

@storm-stack/date-time

Version:

This package includes a DateTime class, various utility functions for working with dates and times, and a number of formatting options.

60 lines (59 loc) 1.65 kB
import type { Temporal } from "@js-temporal/polyfill"; import { StormDateTime } from "../storm-date-time"; /** * Options for the `formatSince` method */ export type FormatSinceOptions = { /** * Whether to use colon notation */ colonNotation?: boolean; /** * Whether to use compact notation */ compact?: boolean; /** * Whether to format sub-milliseconds */ formatSubMilliseconds?: boolean; /** * Whether to keep decimals on whole seconds */ keepDecimalsOnWholeSeconds?: boolean; /** * The number of decimal digits to use for milliseconds */ millisecondsDecimalDigits?: number; /** * The number of decimal digits to use for seconds */ secondsDecimalDigits?: number; /** * Whether to separate milliseconds */ separateMilliseconds?: boolean; /** * The number of units to include */ unitCount?: number; /** * Whether to use verbose notation */ verbose?: boolean; }; /** * Formats a duration or a date-time since another date-time. * * @remarks * An example output when the options.verbose is true: * 4 days 3 hours 2 minutes 1 second 0 milliseconds * * An example output when the options.verbose is false: * 4d 3h 2m 1s 0ms * * @param dateTimeOrDuration - The date-time or duration to format * @param dateTimeTo - The date-time to format since * @param options - The options to use * @returns The formatted time since */ export declare const formatSince: (dateTimeOrDuration: StormDateTime | Temporal.Duration, dateTimeTo?: StormDateTime, options?: FormatSinceOptions) => string;