Compare commits
4 Commits
a777e585e8
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| e189cb3b73 | |||
| 8f14196418 | |||
| acf1728cb9 | |||
| 722e674526 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@tp/tp-date-input",
|
||||
"version": "2.0.2",
|
||||
"version": "2.1.1",
|
||||
"description": "",
|
||||
"main": "tp-date-input.js",
|
||||
"scripts": {
|
||||
|
||||
+12
-9
@@ -292,7 +292,7 @@ class TpDateInput extends EventHelpers(ControlState(FormElement(LitElement))) {
|
||||
}
|
||||
|
||||
// Convert luxon format to match input assignment
|
||||
const luxonFormat = this._inputAssign.map(part => {
|
||||
const format = this._inputAssign.map(part => {
|
||||
switch (part) {
|
||||
case 'MM': return 'LL';
|
||||
case 'dd': return 'dd';
|
||||
@@ -301,17 +301,18 @@ class TpDateInput extends EventHelpers(ControlState(FormElement(LitElement))) {
|
||||
}
|
||||
}).join('-');
|
||||
|
||||
const dt = DateTime.fromFormat(i0 + '-' + i1 + '-' + i2, luxonFormat);
|
||||
// Parse the entered values as a plain calendar date, then store as UTC midnight.
|
||||
// Date-only fields are timezone-agnostic — April 7 means April 7 for everyone.
|
||||
const dt = DateTime.fromFormat(i0 + '-' + i1 + '-' + i2, format);
|
||||
|
||||
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();
|
||||
const utcMidnight = DateTime.utc(dt.year, dt.month, dt.day);
|
||||
this.date = utcMidnight.toJSDate();
|
||||
this.value = utcMidnight.toISO();
|
||||
this.invalid = false;
|
||||
this.dispatchEvent(new CustomEvent('value-changed', { detail: this.value, bubbles: true, composed: true }));
|
||||
} else {
|
||||
@@ -465,9 +466,10 @@ 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 luxon format parts to match display format
|
||||
// Values are stored as UTC midnight — display the UTC calendar date as-is.
|
||||
dt = dt.toUTC();
|
||||
this._input0 = dt.toFormat(this._getLuxonFormat(this._inputAssign[0]));
|
||||
this._input1 = dt.toFormat(this._getLuxonFormat(this._inputAssign[1]));
|
||||
this._input2 = dt.toFormat(this._getLuxonFormat(this._inputAssign[2]));
|
||||
@@ -488,7 +490,8 @@ class TpDateInput extends EventHelpers(ControlState(FormElement(LitElement))) {
|
||||
if (this.today) {
|
||||
setTimeout(() => {
|
||||
if (!this.value) {
|
||||
this.value = DateTime.now().toISO();
|
||||
const now = DateTime.utc();
|
||||
this.value = DateTime.utc(now.year, now.month, now.day).toISO();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user