mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 17:32:15 +03:00
100dea6d98
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
59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import moment from 'moment';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
export default class PublishAtOption extends Component {
|
|
@service settings;
|
|
|
|
@action
|
|
setDate(selectedDate) {
|
|
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);
|
|
}
|
|
|
|
@action
|
|
setTime(time, event) {
|
|
const newDate = moment.tz(this.args.publishOptions.scheduledAtUTC, this.settings.get('timezone'));
|
|
|
|
// used to reset the time value on blur if it's invalid
|
|
const oldTime = newDate.format('HH:mm');
|
|
|
|
if (!time) {
|
|
event.target.value = oldTime;
|
|
return;
|
|
}
|
|
|
|
if (time.match(/^\d:\d\d$/)) {
|
|
time = `0${time}`;
|
|
}
|
|
|
|
if (!time.match(/^\d\d:\d\d$/)) {
|
|
event.target.value = oldTime;
|
|
return;
|
|
}
|
|
|
|
const [hour, minute] = time.split(':').map(n => parseInt(n, 10));
|
|
|
|
if (isNaN(hour) || hour < 0 || hour > 23 || isNaN(minute) || minute < 0 || minute > 59) {
|
|
event.target.value = oldTime;
|
|
return;
|
|
}
|
|
|
|
newDate.set({hour, minute});
|
|
this.args.publishOptions.setScheduledAt(newDate);
|
|
}
|
|
}
|