Change Intl.DateTimeFormat() into toLocaleString() for iOS < 14

This commit is contained in:
the-djmaze 2022-12-23 19:03:35 +01:00
parent 508c262a4b
commit a83cb9150e
2 changed files with 3 additions and 8 deletions

View file

@ -135,7 +135,7 @@ export const
timeToNode = (element, time) => {
try {
if (time) {
element.dateTime = (new Date(time * 1000)).format('ISO8601');
element.dateTime = new Date(time * 1000).toISOString();
} else {
time = Date.parse(element.dateTime) / 1000;
}

9
dev/prototype.js vendored
View file

@ -12,17 +12,12 @@
let formats = {
LT : {timeStyle: 'short'},
LLL : {dateStyle: 'long', timeStyle: 'short'}
},
pad2 = v => 10 > v ? '0' + v : v;
};
// Format momentjs/PHP date formats to Intl.DateTimeFormat
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
Date.prototype.format = function (options, UTC, hourCycle) {
if (typeof options == 'string') {
if ('ISO8601' == options) {
return this.getFullYear() + '-' + pad2(1 + this.getMonth()) + '-' + pad2(this.getDate())
+ 'T' + pad2(this.getHours()) + ':' + pad2(this.getMinutes()) + ':' + pad2(this.getSeconds());
}
if (formats[options]) {
options = formats[options];
} else {
@ -33,7 +28,7 @@
if (hourCycle) {
options.hourCycle = hourCycle;
}
return new Intl.DateTimeFormat(doc.documentElement.lang, options).format(this);
return this.toLocaleString(doc.documentElement.lang, options);
};
Element.prototype.closestWithin = function(selector, parent) {