web: fix dateTimeLocal() dropping local timezone
closes #2860 Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
f391c33bdf
commit
4da350ebfc
|
@ -97,6 +97,10 @@ export function dateTimeLocal(date: Date): string {
|
||||||
// milliseconds, which the input field doesn't like (on chrome, on firefox its fine)
|
// 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
|
// On chrome, setting .valueAsNumber works, but that causes an error on firefox, so go
|
||||||
// figure.
|
// 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]}`;
|
return `${parts[0]}:${parts[1]}`;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue