UNPKG

svelte-ux

Version:

- Increment version in `package.json` and commit as `Version bump to x.y.z` - `npm run publish`

23 lines (22 loc) 1.01 kB
import { format as dateFormat } from 'date-fns'; import { formatDate, utcToLocalDate } from './date'; export function dateDisplay(value, options) { let date = value != null ? (value instanceof Date ? value : new Date(value)) : null; // Offset for UTC if (options === null || options === void 0 ? void 0 : options.utc) { date = utcToLocalDate(date); } let formattedDate = ''; if (date) { if (options === null || options === void 0 ? void 0 : options.format) { formattedDate = dateFormat(date, options === null || options === void 0 ? void 0 : options.format); } else if (options === null || options === void 0 ? void 0 : options.periodType) { formattedDate = formatDate(date, options === null || options === void 0 ? void 0 : options.periodType, options === null || options === void 0 ? void 0 : options.variant); } else { formattedDate = date.toLocaleString(); } } return formattedDate; }