From fa92a62cd36b47855e0831439d9814b7ab6a61bc Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Fri, 1 Jul 2022 00:36:40 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20scheduled=20post=20datep?= =?UTF-8?q?icker=20sometimes=20picking=20day=20before=20selected=20date?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no issue - in sites with a timezone that is negatively offset from UTC at certain times of day when the equivalent UTC date would be the next day, selecting a date when scheduling a post would select a day before the selected date - fixed the date adjustment when applying the selected date to properly take timezones into account --- .../components/editor/publish-options/publish-at.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ghost/admin/app/components/editor/publish-options/publish-at.js b/ghost/admin/app/components/editor/publish-options/publish-at.js index 969caca757..e59c2c8c75 100644 --- a/ghost/admin/app/components/editor/publish-options/publish-at.js +++ b/ghost/admin/app/components/editor/publish-options/publish-at.js @@ -8,11 +8,19 @@ export default class PublishAtOption extends Component { @action setDate(selectedDate) { - const newDate = moment(this.args.publishOptions.scheduledAtUTC); - const {years, months, date} = moment(selectedDate).toObject(); + const selectedMoment = moment(selectedDate); + const {years, months, date} = selectedMoment.toObject(); + // Create a new moment from existing scheduledAtUTC _in site timezone_. + // This ensures we're setting the date correctly because we don't need + // to account for the converted UTC date being yesterday/tomorrow. + const newDate = moment.tz( + this.args.publishOptions.scheduledAtUTC, + this.settings.get('timezone') + ); newDate.set({years, months, date}); + // converts back to UTC this.args.publishOptions.setScheduledAt(newDate); }