mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
adjust cron so that it prevents a double cron when timezone decreases (timezoneOffset increases)
* start to fix cron for when timezones change * add some incomplete code * change cron to identify when timezone changes and run only if both zones agree it should run - BAD - does cron an hour early one day later * change timezone offset variable names * improve handling of each individual timezone change possibility * remove unnecessary casting to number * remove duplicated code * finish code for dangerous timezone change * fix linting errors * remove console.log lines and other testing code * add a TODO comment for further actions for timezone changes in the "safe" direction
This commit is contained in:
@@ -25,8 +25,21 @@ export const DAY_MAPPING = {
|
||||
function sanitizeOptions (o) {
|
||||
let ref = Number(o.dayStart || 0);
|
||||
let dayStart = !_.isNaN(ref) && ref >= 0 && ref <= 24 ? ref : 0;
|
||||
let timezoneOffset = o.timezoneOffset ? Number(o.timezoneOffset) : Number(moment().zone());
|
||||
// TODO: check and clean timezoneOffset as for dayStart (e.g., might not be a number)
|
||||
|
||||
let timezoneOffset;
|
||||
let timezoneOffsetDefault = Number(moment().zone());
|
||||
if (_.isFinite(o.timezoneOffsetOverride)) {
|
||||
timezoneOffset = Number(o.timezoneOffsetOverride);
|
||||
} else if (_.isFinite(o.timezoneOffset)) {
|
||||
timezoneOffset = Number(o.timezoneOffset);
|
||||
} else {
|
||||
timezoneOffset = timezoneOffsetDefault;
|
||||
}
|
||||
if (timezoneOffset > 720 || timezoneOffset < -840) {
|
||||
// timezones range from -12 (offset +720) to +14 (offset -840)
|
||||
timezoneOffset = timezoneOffsetDefault;
|
||||
}
|
||||
|
||||
let now = o.now ? moment(o.now).zone(timezoneOffset) : moment().zone(timezoneOffset);
|
||||
|
||||
// return a new object, we don't want to add "now" to user object
|
||||
|
||||
Reference in New Issue
Block a user