From 2502639a86d03d9ebb21d1aeb3699db0b81f01da Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Mon, 23 May 2022 22:12:37 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20timezone=20related=20iss?= =?UTF-8?q?ues=20when=20scheduling=20posts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no issue - fixed incorrect conversion of time when converting between site tz and utc when setting scheduled hour/minute in publish flow - we initially created a UTC `newDate` moment from `publishOptions.scheduledAtUTC` but then used `newDate.tz(siteTimezone).format()` to get the time which was the source of the bug, it was assumed that was a non-destructive action returning a new date but it actually changed the underlying date resulting in the later calculations causing timezone adjustments to be applied twice - simplified by not converting to UTC inside the publish-at component as that's already handled inside PublishOptions - fixed time not resetting to minimum schedule time when set to earlier date than allowed --- .../editor-labs/publish-options/publish-at.js | 14 +++----------- ghost/admin/app/utils/publish-options.js | 1 + 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/ghost/admin/app/components/editor-labs/publish-options/publish-at.js b/ghost/admin/app/components/editor-labs/publish-options/publish-at.js index 54496a6a4b..f1b64651e5 100644 --- a/ghost/admin/app/components/editor-labs/publish-options/publish-at.js +++ b/ghost/admin/app/components/editor-labs/publish-options/publish-at.js @@ -18,11 +18,10 @@ export default class PublishAtOption extends Component { @action setTime(time, event) { - const newDate = moment.utc(this.args.publishOptions.scheduledAtUTC); + const newDate = moment.tz(this.args.publishOptions.scheduledAtUTC, this.settings.get('timezone')); // used to reset the time value on blur if it's invalid - // TODO: handle this in the picker component instead - const oldTime = newDate.tz(this.settings.get('timezone')).format('HH:mm'); + const oldTime = newDate.format('HH:mm'); if (!time) { event.target.value = oldTime; @@ -45,14 +44,7 @@ export default class PublishAtOption extends Component { return; } - // hour/minute will be the site timezone equivalent but we need the hour/minute - // as it would be in UTC - const conversionDate = moment().tz(this.settings.get('timezone')); - conversionDate.set({hour, minute}); - const utcDate = moment.utc(conversionDate); - - newDate.set({hour: utcDate.get('hour'), minute: utcDate.get('minute')}); - + newDate.set({hour, minute}); this.args.publishOptions.setScheduledAt(newDate); } } diff --git a/ghost/admin/app/utils/publish-options.js b/ghost/admin/app/utils/publish-options.js index d7b3f66466..5bd5abfd33 100644 --- a/ghost/admin/app/utils/publish-options.js +++ b/ghost/admin/app/utils/publish-options.js @@ -64,6 +64,7 @@ export default class PublishOptions { date = moment.utc(date).milliseconds(0); if (date.isBefore(this.minScheduledAt)) { + this.scheduledAtUTC = this.minScheduledAt; return; }