@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
36 lines (35 loc) • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.formatDate = formatDate;
exports.formatDateRange = formatDateRange;
var _defaults = require("../../shared/defaults");
var _DatePickerCalc = require("../date-picker/DatePickerCalc");
function formatDate(dateValue) {
let {
locale = _defaults.LOCALE,
options = {
dateStyle: 'short'
}
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
const date = (0, _DatePickerCalc.convertStringToDate)(dateValue);
return typeof Intl !== 'undefined' ? new Intl.DateTimeFormat(locale, options).format(date) : date.toLocaleString(locale, options);
}
function formatDateRange(dates) {
let {
locale = _defaults.LOCALE,
options = {
dateStyle: 'long'
}
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
const startDate = (0, _DatePickerCalc.convertStringToDate)(dates.startDate);
const endDate = (0, _DatePickerCalc.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