UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

29 lines 1.18 kB
import { LOCALE as defaultLocale } from '../../shared/defaults'; import { convertStringToDate } from '../date-picker/DatePickerCalc'; export function formatDate(dateValue) { let { locale = defaultLocale, options = { dateStyle: 'short' } } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; const date = convertStringToDate(dateValue); return typeof Intl !== 'undefined' ? new Intl.DateTimeFormat(locale, options).format(date) : date.toLocaleString(locale, options); } export function formatDateRange(dates) { let { locale = defaultLocale, options = { dateStyle: 'long' } } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 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