Skip to content

Commit

Permalink
web: fix dateTimeLocal() dropping local timezone
Browse files Browse the repository at this point in the history
closes #2860

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
  • Loading branch information
BeryJu committed May 14, 2022
1 parent f391c33 commit 4da350e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion web/src/utils.ts
Expand Up @@ -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]}`;
}

0 comments on commit 4da350e

Please sign in to comment.