salix-front/src/filters/toDate.js

17 lines
414 B
JavaScript
Raw Normal View History

2022-10-17 14:23:19 +00:00
import { useI18n } from 'vue-i18n';
2022-10-25 12:23:59 +00:00
export default function (value, options = {}) {
2022-10-17 14:23:19 +00:00
if (!value) return;
2023-03-01 15:20:28 +00:00
if (!options.dateStyle && !options.timeStyle) {
2023-02-23 14:01:40 +00:00
options.day = '2-digit';
options.month = '2-digit';
options.year = 'numeric';
}
2022-10-25 12:23:59 +00:00
2022-10-17 14:23:19 +00:00
const { locale } = useI18n();
const date = new Date(value);
2023-02-23 14:01:40 +00:00
return new Intl.DateTimeFormat(locale.value, options).format(date);
}