Make sure value is always UTC and timeZone is applied to the user input if provided.
This commit is contained in:
@@ -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": {
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user