From 4da350ebfcaacc53d74fe08d39e1ff42b78e9449 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 14 May 2022 12:42:13 +0200 Subject: [PATCH] web: fix dateTimeLocal() dropping local timezone closes #2860 Signed-off-by: Jens Langhammer --- web/src/utils.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web/src/utils.ts b/web/src/utils.ts index 5713acb44..369c5a757 100644 --- a/web/src/utils.ts +++ b/web/src/utils.ts @@ -97,6 +97,10 @@ export function dateTimeLocal(date: Date): string { // milliseconds, which the input field doesn't like (on chrome, on firefox its fine) // On chrome, setting .valueAsNumber works, but that causes an error on firefox, so go // figure. - const parts = date.toISOString().split(":"); + // Additionally, toISOString always returns the date without timezone, which we would like + // to include for better usability + const tzOffset = new Date().getTimezoneOffset() * 60000; //offset in milliseconds + const localISOTime = new Date(date.getTime() - tzOffset).toISOString().slice(0, -1); + const parts = localISOTime.split(":"); return `${parts[0]}:${parts[1]}`; }