UNPKG

@lloydjatkinson/date-fns-additional

Version:
89 lines (88 loc) 4.63 kB
/** * Human friendly date time format names. * * @see {@link FormatPattern} * * @remarks * The `relative` format is under review. Currently, it has simple Today/Yesterday/(date) logic. * This functionality is probably either too limited or should be under a different name and built on * more generic logic. */ export type FormatName = 'date-month-year-and-twelve-hour-time-with-period' | 'date-year-month-date' | 'month-name-with-day-number' | 'month-name-with-ordinal-date' | 'month-with-year' | 'relative' | 'twelve-hour-time-with-period' | 'twelve-hour-time' | 'twenty-four-hour-time' | 'year'; /** * Format specifiers for designated format names. * @see {@link FormatName} */ export type FormatPattern = 'dd/MM/yyyy - hh:mm a' | 'h:mm a' | 'h:mm' | 'HH:mm' | 'LLLL d' | 'MMMM yyyy' | 'PPP' | 'yyyy-MM-dd' | 'yyyy'; /** * Formats a Date using the specified {@link FormatPattern}. Note the similarity to the {@link formatUsingPattern} function. * Both functions format the date based on the format pattern, it is simply a choice of whether to use the {@link FormatName} or {@link FormatPattern}. * Which function is more appropriate to use depends on the use case. * @param { Date } date The date. * @param { FormatPattern } pattern The format pattern. * @returns { string } The formatted string. */ export declare const formatUsingPattern: (date: Date, pattern: FormatPattern) => string; /** * Formats a Date into "twelve hour time". For example, 3:23. This is "h:mm" format from date-fns. * @param { Date } date The date. * @returns { string } The formatted string. */ export declare const formatAsTwelveHourTime: (date: Date) => string; /** * Formats a Date into "twelve hour time with period". For example, 3:23 PM. This is "h:mm a" format from date-fns. * @param { Date } date The date. * @returns { string } The formatted string. */ export declare const formatAsTwelveHourTimeWithPeriod: (date: Date) => string; /** * Formats a Date into "twenty four hour time". For example, 3:23. This is "HH:mm" format from date-fns. * @param { Date } date The date. * @returns { string } The formatted string. */ export declare const formatAsTwentyFourHourTime: (date: Date) => string; /** * Formats a Date into "month name with day number". For example, October 21. This is "LLLL d" format from date-fns. * @param { Date } date The date. * @returns { string } The formatted string. */ export declare const formatAsMonthNameWithDayNumber: (date: Date) => string; /** * Formats a Date into "month name with day number". For example, October 21. This is "PPP" format from date-fns. * @param { Date } date The date. * @returns { string } The formatted string. */ export declare const formatAsMonthNameWithOrdinalDate: (date: Date) => string; /** * Formats a Date into "date month year and with twelve hour time". For example, 13/05/2021 - 03:50 PM * @param { Date } date The date. * @returns { string } The formatted string. */ export declare const formatAsDateMonthYearAndTwelveHourTimeWithPeriod: (date: Date) => string; /** * Formats a Date into "date in ISO format without the time". For example, 2022-11-29. * @param { Date } date The date. * @returns { string } The formatted string. */ export declare const formatAsIsoDate: (date: Date) => string; /** * Formats a Date into "relative date". For example, a date that is today would be formatted as "Today". * @example * formatAsRelativeDate(new Date(2020, 10, 21), new Date(2020, 10, 21)) // Today * formatAsRelativeDate(new Date(2020, 10, 20), new Date(2020, 10, 21)) // Yesterday * formatAsRelativeDate(new Date(2020, 10, 19), new Date(2020, 10, 21)) // October 19 * @param { Date } date The date. * @param { Date } baseDate The date from which to calculate the relative formatting. * @returns { string } The formatted string. */ export declare const formatAsRelativeDate: (date: Date, baseDate: Date) => string; /** * Formats a Date using the specified {@link FormatName}. Note the similarity to the {@link formatUsingPattern} function. * This function is a convenient wrapper around {@link formatUsingPattern} that provides the ability to format based on {@link FormatName}. * Both functions format the date based on the format pattern, it is simply a choice of whether to use the {@link FormatName} or {@link FormatPattern}. * Which function is more appropriate to use depends on the use case. * @param { Date } date The date. * @param { FormatPattern } pattern The format pattern. * @returns { string } The formatted string. */ export declare const formatUsingName: (date: Date, formatName: FormatName) => string;