Returned date should always in UTC. Timezone is only for display.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user