@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
58 lines (56 loc) • 1.32 kB
JavaScript
import { CachedIntl } from "../utils/intl.mjs";
import configuration from "@intlayer/config/built";
//#region src/formatters/date.ts
const presets = {
short: {
year: "2-digit",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit"
},
long: {
year: "numeric",
month: "long",
day: "numeric",
hour: "numeric",
minute: "numeric"
},
full: {
year: "numeric",
month: "long",
day: "numeric",
hour: "numeric",
minute: "numeric",
hour12: false
},
dateOnly: {
year: "numeric",
month: "short",
day: "numeric"
},
timeOnly: {
hour: "numeric",
minute: "numeric",
second: "numeric"
}
};
/**
* Formats a date/time value into a localized string using Intl.DateTimeFormat.
*
* @example
* date({ date: new Date(), options: "short" });
* // "08/02/25, 14:30"
*
* @example
* date({ date: "2025-08-02T14:30:00Z", locale: Locales.FRENCH, options: { month: "long", day: "numeric" } });
* // "2 août"
*/
const date = (date$1, options) => {
const dateTime = new Date(date$1);
const resolvedOptions = typeof options === "string" ? presets[options] ?? {} : options;
return new CachedIntl.DateTimeFormat(options?.locale ?? configuration?.internationalization?.defaultLocale, resolvedOptions).format(dateTime);
};
//#endregion
export { date };
//# sourceMappingURL=date.mjs.map