fix(web): fix datetime to local ISO string converter
This commit is contained in:
parent
4f0c1cfdc2
commit
0617bf2a8f
@ -1,5 +1,5 @@
|
|||||||
function datetimeToLocalISO(datetime) {
|
function datetimeToLocalISO(datetime) {
|
||||||
var options = {
|
options = {
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
month: "2-digit",
|
month: "2-digit",
|
||||||
day: "2-digit",
|
day: "2-digit",
|
||||||
@ -8,20 +8,20 @@ function datetimeToLocalISO(datetime) {
|
|||||||
second: "2-digit",
|
second: "2-digit",
|
||||||
timeZoneName: "longOffset",
|
timeZoneName: "longOffset",
|
||||||
};
|
};
|
||||||
var formatter = new Intl.DateTimeFormat("sv-SE", options);
|
formatter = new Intl.DateTimeFormat("iso", options);
|
||||||
var date = new Date(datetime);
|
date = new Date(datetime);
|
||||||
return formatter
|
parts = {}
|
||||||
|
formatter
|
||||||
.formatToParts(date)
|
.formatToParts(date)
|
||||||
.map(({ type, value }) => {
|
.map(({ type, value }) => {
|
||||||
if (type === "timeZoneName") {
|
if (type === "timeZoneName") {
|
||||||
return value.slice(3);
|
value = value.slice(3);
|
||||||
} else {
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
})
|
if (type !== "literal") {
|
||||||
.join("")
|
parts[type] = value;
|
||||||
.replace(" ", "T")
|
}
|
||||||
.replace(" ", "");
|
});
|
||||||
|
return `${parts.year}-${parts.month}-${parts.day}T${parts.hour}:${parts.minute}:${parts.second}${parts.timeZoneName}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function escapedString(str) {
|
function escapedString(str) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user