fix(web): fix datetime to local ISO string converter

This commit is contained in:
Masahiko AMANO 2025-01-07 16:14:22 +03:00
parent 4f0c1cfdc2
commit 0617bf2a8f

View File

@ -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) {