diff --git a/app/assets/javascripts/discourse/app/components/date-input.js b/app/assets/javascripts/discourse/app/components/date-input.js index 16f12351120..61192bc5e59 100644 --- a/app/assets/javascripts/discourse/app/components/date-input.js +++ b/app/assets/javascripts/discourse/app/components/date-input.js @@ -54,7 +54,7 @@ export default Component.extend({ if (this._picker && this.date) { const parsedDate = this.date instanceof moment ? this.date : moment(this.date); - this._picker.setDate(parsedDate.toDate(), true); + this._picker.setDate(parsedDate, true); } }); }); @@ -66,7 +66,7 @@ export default Component.extend({ if (this._picker && this.date) { const parsedDate = this.date instanceof moment ? this.date : moment(this.date); - this._picker.setDate(parsedDate.toDate(), true); + this._picker.setDate(parsedDate, true); } if (this._picker && this.relativeDate) { @@ -75,7 +75,7 @@ export default Component.extend({ ? this.relativeDate : moment(this.relativeDate); - this._picker.setMinDate(parsedRelativeDate.toDate(), true); + this._picker.setMinDate(parsedRelativeDate, true); } if (this._picker && !this.date) { diff --git a/app/assets/javascripts/discourse/app/components/date-time-input.js b/app/assets/javascripts/discourse/app/components/date-time-input.js index 864c1aeacbb..718f700b22c 100644 --- a/app/assets/javascripts/discourse/app/components/date-time-input.js +++ b/app/assets/javascripts/discourse/app/components/date-time-input.js @@ -66,7 +66,7 @@ export default Component.extend({ ); }, - @computed + @computed("timezone") get resolvedTimezone() { return this.timezone || moment.tz.guess(); }, diff --git a/app/assets/javascripts/discourse/tests/integration/components/date-input-test.js b/app/assets/javascripts/discourse/tests/integration/components/date-input-test.js index af0ce661bbc..e2b03834622 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/date-input-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/date-input-test.js @@ -54,4 +54,20 @@ module("Integration | Component | date-input", function (hooks) { assert.ok(this.date.isSame(moment("2019-02-02"))); }); + + test("always shows date in timezone of input timestamp", async function (assert) { + this.setProperties({ + date: moment.tz("2023-05-05T10:00:00", "ETC/GMT-12"), + }); + + await render( + hbs`` + ); + assert.strictEqual(dateInput().value, "2023-05-05"); + + this.setProperties({ + date: moment.tz("2023-05-05T10:00:00", "ETC/GMT+12"), + }); + assert.strictEqual(dateInput().value, "2023-05-05"); + }); }); diff --git a/app/assets/javascripts/discourse/tests/integration/components/date-time-input-test.js b/app/assets/javascripts/discourse/tests/integration/components/date-time-input-test.js index 52cdbc6f242..d64680a1ab2 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/date-time-input-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/date-time-input-test.js @@ -63,4 +63,23 @@ module("Integration | Component | date-time-input", function (hooks) { assert.notOk(exists(timeInput())); }); + + test("supports swapping timezone without changing visible date/time", async function (assert) { + this.setProperties({ + date: moment.tz("2023-05-05T12:00:00", "Europe/London"), + timezone: "Europe/London", + onChange: setDate, + }); + + await render( + hbs`` + ); + dateInput().dispatchEvent(new Event("change")); + assert.strictEqual(this.date.format(), "2023-05-05T12:00:00+01:00"); + + this.setProperties({ timezone: "Australia/Sydney" }); + + dateInput().dispatchEvent(new Event("change")); + assert.strictEqual(this.date.format(), "2023-05-05T12:00:00+10:00"); + }); });