Skip to content

Commit

Permalink
Merge pull request origo-map#1700 from origo-map/timestamp-format
Browse files Browse the repository at this point in the history
feature: support timestamp when formatDatetime
  • Loading branch information
johnnyblasta authored Mar 6, 2023
2 parents 50f2fa1 + 4f40a4c commit 602be73
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/getattributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 602be73

Please sign in to comment.