Make sure value is always UTC and timeZone is applied to the user input if provided.

This commit is contained in:
2026-03-24 11:45:09 +01:00
parent a777e585e8
commit 722e674526
2 changed files with 12 additions and 4 deletions

View File

@@ -308,10 +308,18 @@ class TpDateInput extends EventHelpers(ControlState(FormElement(LitElement))) {
this.inputs[1].invalid = false;
this.inputs[2].invalid = false;
// Convert to specified timezone or use system timezone
const finalDt = this.timeZone ? dt.setZone(this.timeZone) : dt;
// If timeZone is specified, interpret the entered date values as being in that timezone
// and output as UTC. This ensures filters work correctly against UTC-stored dates.
let finalDt;
if (this.timeZone) {
// keepLocalTime: true interprets the entered values as being in the specified timezone
finalDt = this.timeZone ? dt.setZone(this.timeZone, { keepLocalTime: true }) : dt;
} else {
finalDt = dt;
}
this.date = finalDt.toJSDate();
this.value = finalDt.toISO();
this.value = finalDt.toUTC().toISO();
this.invalid = false;
this.dispatchEvent(new CustomEvent('value-changed', { detail: this.value, bubbles: true, composed: true }));
} else {