Make sure component always returns midnight utc.

This commit is contained in:
2026-04-10 09:53:39 +02:00
parent 093ab1372d
commit e714044854
2 changed files with 3 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@tp/tp-date-picker",
"version": "3.0.1",
"version": "3.0.2",
"description": "",
"main": "tp-date-picker.js",
"scripts": {

View File

@@ -290,15 +290,9 @@ class TpDatePicker extends FormElement(LitElement) {
for (const el of e.composedPath()) {
if (el.date !== undefined) {
this.value = el.date;
// 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();
// Date-only fields always store UTC midnight — the calendar date is timezone-agnostic.
const outputValue = DateTime.utc(selectedDate.year, selectedDate.month, selectedDate.day).toISO();
this.dispatchEvent(new CustomEvent('value-changed', { detail: outputValue, bubbles: true, composed: true }));
return;
}