Move from deprecated moment#zone to moment#utcOffset (#12207)

* Issue 10209 - Remove read usages of zone

* Issue 10209 - Add coverage on daysSince and startOfDay cron utility functions

* Issue 10209 - Add unit test for daysUserHasMissed method

* Issue 10209 - Remove usages of deprecated `moment.js#zone` method.

* Issue 10209 - Add helper function to centralise logic

Also simplify timezoneOffsetToUtc function in site.vue

* Issue 10209 - Also add getUtcOffset as method on user

Co-authored-by: Matteo Pagliazzi <matteopagliazzi@gmail.com>
This commit is contained in:
Bart Enkelaar
2020-07-25 13:22:41 +02:00
committed by GitHub
parent c10b9b7993
commit 234258b41e
25 changed files with 413 additions and 141 deletions

View File

@@ -172,7 +172,7 @@ function resetHabitCounters (user, tasksByType, now, daysMissed) {
break;
}
const thatDay = moment(now)
.zone(user.preferences.timezoneOffset + user.preferences.dayStart * 60)
.utcOffset(user.getUtcOffset() - user.preferences.dayStart * 60)
.subtract({ days: i });
if (thatDay.day() === 1) {
resetWeekly = true;
@@ -281,14 +281,14 @@ function awardLoginIncentives (user) {
// Perform various beginning-of-day reset actions.
export function cron (options = {}) {
const {
user, tasksByType, analytics, now = new Date(), daysMissed, timezoneOffsetFromUserPrefs,
user, tasksByType, analytics, now = new Date(), daysMissed, timezoneUtcOffsetFromUserPrefs,
} = options;
let _progress = { down: 0, up: 0, collectedItems: 0 };
// Record pre-cron values of HP and MP to show notifications later
const beforeCronStats = _.pick(user.stats, ['hp', 'mp']);
user.preferences.timezoneOffsetAtLastCron = timezoneOffsetFromUserPrefs;
user.preferences.timezoneOffsetAtLastCron = -timezoneUtcOffsetFromUserPrefs;
// User is only allowed a certain number of drops a day. This resets the count.
if (user.items.lastDrop.count > 0) user.items.lastDrop.count = 0;