From c66db8cd867e937d2ad2678af1c9afc398bf2711 Mon Sep 17 00:00:00 2001 From: pk Date: Tue, 7 Apr 2026 11:01:25 +0200 Subject: [PATCH] Returned date should always in UTC. Timezone is only for display. --- tp-date-picker.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tp-date-picker.js b/tp-date-picker.js index afe6660..695959b 100644 --- a/tp-date-picker.js +++ b/tp-date-picker.js @@ -220,6 +220,7 @@ class TpDatePicker extends FormElement(LitElement) { yearsBackwards: { type: Number }, showYearSelector: { type: Boolean }, 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()) { if (el.date !== undefined) { 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; } }