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

@@ -1,6 +1,6 @@
{ {
"name": "@tp/tp-date-input", "name": "@tp/tp-date-input",
"version": "2.0.2", "version": "2.0.3",
"description": "", "description": "",
"main": "tp-date-input.js", "main": "tp-date-input.js",
"scripts": { "scripts": {

View File

@@ -308,10 +308,18 @@ class TpDateInput extends EventHelpers(ControlState(FormElement(LitElement))) {
this.inputs[1].invalid = false; this.inputs[1].invalid = false;
this.inputs[2].invalid = false; this.inputs[2].invalid = false;
// Convert to specified timezone or use system timezone // If timeZone is specified, interpret the entered date values as being in that timezone
const finalDt = this.timeZone ? dt.setZone(this.timeZone) : dt; // 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.date = finalDt.toJSDate();
this.value = finalDt.toISO(); this.value = finalDt.toUTC().toISO();
this.invalid = false; this.invalid = false;
this.dispatchEvent(new CustomEvent('value-changed', { detail: this.value, bubbles: true, composed: true })); this.dispatchEvent(new CustomEvent('value-changed', { detail: this.value, bubbles: true, composed: true }));
} else { } else {