0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-25 02:31:59 -05:00

🐛 Fixed timezone related issues when scheduling posts

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
This commit is contained in:
Kevin Ansfield 2022-05-23 22:12:37 +01:00
parent a559f4c686
commit 2502639a86
2 changed files with 4 additions and 11 deletions

View file

@ -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);
}
}

View file

@ -64,6 +64,7 @@ export default class PublishOptions {
date = moment.utc(date).milliseconds(0);
if (date.isBefore(this.minScheduledAt)) {
this.scheduledAtUTC = this.minScheduledAt;
return;
}