From 4f40a4c88fec235baa3af2f5e44386d396def717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Bl=C3=A4sta?= Date: Fri, 3 Mar 2023 15:52:09 +0100 Subject: [PATCH] feature: support timestamp when formatDatetime --- src/getattributes.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/getattributes.js b/src/getattributes.js index 364b86b7b..798dcc08c 100644 --- a/src/getattributes.js +++ b/src/getattributes.js @@ -84,10 +84,12 @@ const getContent = { suffix = attribute.suffix; } if (attribute.formatDatetime) { + const locale = 'locale' in attribute.formatDatetime ? attribute.formatDatetime.locale : 'default'; + const options = 'options' in attribute.formatDatetime ? attribute.formatDatetime.options : { dateStyle: 'full', timeStyle: 'long' }; if (!Number.isNaN(Date.parse(featureValue))) { - const locale = 'locale' in attribute.formatDatetime ? attribute.formatDatetime.locale : 'default'; - const options = 'options' in attribute.formatDatetime ? attribute.formatDatetime.options : { dateStyle: 'full', timeStyle: 'long' }; val = new Intl.DateTimeFormat(locale, options).format(Date.parse(featureValue)); + } else if (!Number.isNaN(new Date(featureValue).getTime())) { + val = new Intl.DateTimeFormat(locale, options).format(new Date(featureValue)); } } if (attribute.url) {