Skip to content

Dates

Defines a Dictionary of date formatting functions.

Instantiate

TS
function useDateFormats(): UseDateFormats;
function useDateFormats(options: UseDateFormatsOptions): UseDateFormats;

Props

ts
type UseDateFormatsOptions = {
    /**
     * The digitizer instance.
     */
    digitizer?: UseDigitizer;
    /**
     * A translate function or Dictionary.
     */
    translate?: Translator<string> | UseDictionary<string>;
    /**
     * The date format flags.
     */
    formats?: Record<string, DateFlagFormatFunction>;
};
TS
function useDateFormats(): UseDateFormats;
function useDateFormats(options: UseDateFormatsOptions): UseDateFormats;
TS
type UseDateFormatsOptions = {
    /**
     * The digitizer instance.
     */
    digitizer?: UseDigitizer;
    /**
     * A translate function or Dictionary.
     */
    translate?: Translator<string> | UseDictionary<string>;
    /**
     * The date format flags.
     */
    formats?: Record<string, DateFlagFormatFunction>;
};
TS
type DateFlagFormatFunction = (date: Date) => string;

Returns

TS
type UseDateFormats = UseDefinitionMap<DateFlagFormatFunction> & {
    format: (date: Date, format: string) => string;
};

Usage

ts
const { format, parse } = useDateFormats();

format(new Date('2025-01-01'), 'MM/DD/YYYY')); // '01/01/2025'
format(new Date('2025-01-01'), 'DDDD, MMMM YYYY')); // 'Monday, January 2025'

TIP

These are just a few examples and far from complete. If you want to see a feature-complete example, check tests/helpers/date.test.ts in the repo.

Released under the MIT License.