@nethesis/vue-components
Version:
This library contains: - a collection of Vue 3 components based on [Flowbite](https://flowbite.com/) - a set of utility functions
101 lines • 5.95 kB
TypeScript
import { formatDistanceToNowStrict, formatDuration } from 'date-fns';
/**
* Format a date expressed in milliseconds to current locale
*
*/
export declare function formatDateLoc(date: Date | number, fmt: string): string;
export declare const formatInTimeZoneLoc: (date: Date | string | number, fmt: string, tz: string) => string;
export declare const getBrowserLocale: () => string;
/**
* Get date-fns locale. Accepts optional two-letter locale string (e.g., 'en', 'it').
* Defaults to browser language via navigator.language. Falls back to English.
*/
export declare const getDateFnsLocale: (localeArg?: string) => Locale;
/**
* Format a duration expressed in seconds to a human readable value. E.g. 189 -> 3 minutes 9 seconds
*
* @param durationSeconds - duration to format
* @param options - date-fns formatDuration options; 'locale' is always overridden with the current
* locale
*
*/
export declare function formatDurationLoc(durationSeconds: number, options?: Parameters<typeof formatDuration>[1]): string | null;
/**
* Return the approximate and concise distance from a date to now. Example output: '2 hours'.
* Useful to show how long ago something has happened (e.g. a notification timestamp)
*
* @param date - date to compare with now
* @param options - date-fns formatDistanceToNowStrict options; 'locale' is always overridden with
* the current locale
*
* @deprecated Use {@link formatRelativeTime} instead: it produces a complete relative time string
* (e.g. '2 hours ago', 'Yesterday') instead of a bare distance, and relies on
* Intl.RelativeTimeFormat rather than date-fns.
*/
export declare function humanDistanceToNowLoc(date: Date, options?: Parameters<typeof formatDistanceToNowStrict>[1]): string | null;
/**
* Format a date as a relative time string against the current instant, picking the largest
* fitting unit (second, minute, hour, day, week, month, year).
* Past dates yield e.g. '2 hours ago', future dates 'in 2 hours'; dates within the previous or
* next unit yield the idiomatic wording when available (e.g. 'Yesterday', 'Last month').
* The result is capitalized.
*
* Strings are not accepted, because `new Date(string)` parsing is ambiguous. Build the Date at the
* call site instead:
* - ISO 8601 with 'Z' or an offset is safe and portable: `new Date('2026-07-27T10:00:00Z')`
* - epoch seconds: pass the number directly, e.g. `formatRelativeTime(seconds * 1000, locale)`
* - no offset ('2026-07-27T10:00:00') is parsed as LOCAL time; append 'Z' if the value is UTC
* - date-only ('2026-07-27') is parsed as UTC midnight and can render as the wrong day; for local
* midnight use `new Date(2026, 6, 27)`
* - other forms ('2026-07-27 10:00', '27/07/2026') are implementation-defined; do not rely on them
*
* @param date - date to compare with now, or a timestamp in milliseconds
* @param locale - BCP 47 locale tag used by Intl.RelativeTimeFormat (e.g. 'en-GB', 'it')
* @returns the formatted relative time, or '-' if the date is missing or invalid
*
*/
export declare function formatRelativeTime(date: Date | number, locale: string): string;
/**
* Format a date and time using the locale conventions. Example output: '27/07/2026, 15:30:00'.
* When a time zone is provided, the date is converted to it and the short time zone name is
* appended (e.g. '27/07/2026, 15:30:00 GMT+2'); otherwise the local time zone is used.
*
* Strings are not accepted, because `new Date(string)` parsing is ambiguous. Build the Date at the
* call site instead:
* - ISO 8601 with 'Z' or an offset is safe and portable: `new Date('2026-07-27T10:00:00Z')`
* - epoch seconds: pass the number directly, e.g. `formatDateTime(seconds * 1000, locale)`
* - no offset ('2026-07-27T10:00:00') is parsed as LOCAL time; append 'Z' if the value is UTC
* - date-only ('2026-07-27') is parsed as UTC midnight and can render as the wrong day; for local
* midnight use `new Date(2026, 6, 27)`
* - other forms ('2026-07-27 10:00', '27/07/2026') are implementation-defined; do not rely on them
*
* @param dateTime - date to format, or a timestamp in milliseconds
* @param locale - BCP 47 locale tag used by Date.toLocaleString (e.g. 'en-GB', 'it')
* @param timeZone - optional IANA time zone name (e.g. 'Europe/Rome')
* @returns the formatted date and time, or '-' if the date is missing or invalid
*
*/
export declare function formatDateTime(dateTime: Date | number, locale: string, timeZone?: string): string;
/**
* Format a date and time using the locale conventions, omitting seconds and using an abbreviated
* month name. Example output: '27 Jul 2026, 15:30'.
* When a time zone is provided, the date is converted to it and the short time zone name is
* appended (e.g. '27 Jul 2026, 15:30 GMT+2'); otherwise the local time zone is used.
*
* Strings are not accepted, because `new Date(string)` parsing is ambiguous. Build the Date at the
* call site instead:
* - ISO 8601 with 'Z' or an offset is safe and portable: `new Date('2026-07-27T10:00:00Z')`
* - epoch seconds: pass the number directly, e.g. `formatDateTimeNoSeconds(seconds * 1000, locale)`
* - no offset ('2026-07-27T10:00:00') is parsed as LOCAL time; append 'Z' if the value is UTC
* - date-only ('2026-07-27') is parsed as UTC midnight and can render as the wrong day; for local
* midnight use `new Date(2026, 6, 27)`
* - other forms ('2026-07-27 10:00', '27/07/2026') are implementation-defined; do not rely on them
*
* @param dateTime - date to format, or a timestamp in milliseconds
* @param locale - BCP 47 locale tag used by Date.toLocaleString (e.g. 'en-GB', 'it')
* @param timeZone - optional IANA time zone name (e.g. 'Europe/Rome')
* @returns the formatted date and time without seconds, or '-' if the date is missing or invalid
*
*/
export declare function formatDateTimeNoSeconds(dateTime: Date | number, locale: string, timeZone?: string): string;
//# sourceMappingURL=dateTime.d.ts.map