UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

27 lines 1.01 kB
import { LOCALE as defaultLocale } from '../../shared/defaults'; import { convertStringToDate } from '../date-picker/DatePickerCalc'; export function formatDate(dateValue, { locale = defaultLocale, options = { dateStyle: 'short' } } = {}) { const date = convertStringToDate(dateValue); return typeof Intl !== 'undefined' ? new Intl.DateTimeFormat(locale, options).format(date) : date.toLocaleString(locale, options); } export function formatDateRange(dates, { locale = defaultLocale, options = { dateStyle: 'long' } } = {}) { const startDate = convertStringToDate(dates.startDate); const endDate = convertStringToDate(dates.endDate); if (typeof Intl !== 'undefined') { return new Intl.DateTimeFormat(locale, options).formatRange(startDate, endDate); } const startDateString = startDate.toLocaleString(locale, options); const endDateString = endDate.toLocaleString(locale, options); return `${startDateString}-${endDateString}`; } //# sourceMappingURL=DateFormatUtils.js.map