2 Commits

2 changed files with 12 additions and 7 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@tp/tp-date-input",
"version": "2.0.2",
"version": "2.1.0",
"description": "",
"main": "tp-date-input.js",
"scripts": {
+11 -6
View File
@@ -301,17 +301,17 @@ class TpDateInput extends EventHelpers(ControlState(FormElement(LitElement))) {
}
}).join('-');
const dt = DateTime.fromFormat(i0 + '-' + i1 + '-' + i2, luxonFormat);
// Parse the date in the specified timezone (or local if not set).
// This interprets the entered values as being in that timezone.
const dt = DateTime.fromFormat(i0 + '-' + i1 + '-' + i2, luxonFormat, { zone: this.timeZone || 'local' });
if (dt.isValid) {
this.inputs[0].invalid = false;
this.inputs[1].invalid = false;
this.inputs[2].invalid = false;
// Convert to specified timezone or use system timezone
const finalDt = this.timeZone ? dt.setZone(this.timeZone) : dt;
this.date = finalDt.toJSDate();
this.value = finalDt.toISO();
this.date = dt.toJSDate();
this.value = dt.toUTC().toISO();
this.invalid = false;
this.dispatchEvent(new CustomEvent('value-changed', { detail: this.value, bubbles: true, composed: true }));
} else {
@@ -465,8 +465,13 @@ class TpDateInput extends EventHelpers(ControlState(FormElement(LitElement))) {
return;
}
const dt = this._toDateTime(this.value);
let dt = this._toDateTime(this.value);
if (dt && dt.isValid) {
// Convert to user's timezone for display (input values are expected to be UTC)
if (this.timeZone) {
dt = dt.setZone(this.timeZone);
}
// Convert luxon format parts to match display format
this._input0 = dt.toFormat(this._getLuxonFormat(this._inputAssign[0]));
this._input1 = dt.toFormat(this._getLuxonFormat(this._inputAssign[1]));