Returned date should always in UTC. Timezone is only for display.

This commit is contained in:
2026-04-07 11:01:25 +02:00
parent 1df7db4303
commit c66db8cd86

View File

@@ -220,6 +220,7 @@ class TpDatePicker extends FormElement(LitElement) {
yearsBackwards: { type: Number }, yearsBackwards: { type: Number },
showYearSelector: { type: Boolean }, showYearSelector: { type: Boolean },
events: { type: Array }, events: { type: Array },
timeZone: { type: String }, // User's timezone for date interpretation
}; };
} }
@@ -289,7 +290,16 @@ class TpDatePicker extends FormElement(LitElement) {
for (const el of e.composedPath()) { for (const el of e.composedPath()) {
if (el.date !== undefined) { if (el.date !== undefined) {
this.value = el.date; this.value = el.date;
this.dispatchEvent(new CustomEvent('value-changed', { detail: this.value, bubbles: true, composed: true })); // Interpret the selected date as being in the user's timezone, output as UTC ISO string
const selectedDate = el.date;
let outputValue;
const zone = this.timeZone || 'local';
const localDate = DateTime.fromObject(
{ year: selectedDate.year, month: selectedDate.month, day: selectedDate.day },
{ zone }
);
outputValue = localDate.toUTC().toISO();
this.dispatchEvent(new CustomEvent('value-changed', { detail: outputValue, bubbles: true, composed: true }));
return; return;
} }
} }