UNPKG

@alessiofrittoli/date-utils

Version:

Lightweight TypeScript date utility functions library

47 lines (44 loc) 1.93 kB
import { Timezone } from '../timezones/types.js'; export { formatDate } from './formatDate.js'; export { formatRelativeTime } from './formatRelativeTime.js'; import '../timezones/identifiers.js'; type SecondsToUnitReturn<TSkipWeeks extends boolean = false> = { /** Years in given time. */ years: number; /** Months in given time. */ months: number; /** Weeks in given time. */ weeks: TSkipWeeks extends false ? number : null; /** Days in given time. */ days: number; /** Hours in given time. */ hours: number; /** Minutes in given time. */ minutes: number; /** Seconds in given time. */ seconds: number; /** Milliseconds in given time. */ milliseconds: number; microseconds: number; }; /** * Translates seconds into human readable format of milliseconds, seconds, minutes, hours, days, weeks, months and years. * * @see [StackOverflow thread](https://stackoverflow.com/questions/8211744/convert-time-interval-given-in-seconds-into-more-human-readable-form#answer-8211778) * * @param time The number of seconds to be processed. * @returns An object containing the amount of time for each unit. */ declare const secondsToUnit: <TSkipWeeks extends boolean = false>(time: number, skipWeeks?: TSkipWeeks) => SecondsToUnitReturn<TSkipWeeks>; /** * Format date. * * @param date ( Optional ) The date string | milliseconds since UNIX epoch time | Date object. Default: `new Date()`. * @param locale ( Optional ) The Intl.LocalesArgument. * @param options ( Optional ) The Intl.DateTimeFormatOptions. * @returns An object containing the Date object and the localized time string based on the given locale. */ declare const formatLocaleDate: (date?: string | number | Date, locale?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions & { timeZone?: Timezone; }) => string; export { type SecondsToUnitReturn, formatLocaleDate, secondsToUnit };