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

@@ -8,6 +8,8 @@ import {
import i18n from '../i18n';
import updateStats from '../fns/updateStats';
import crit from '../fns/crit';
import getUtcOffset from '../fns/getUtcOffset';
import statsComputed from '../libs/statsComputed';
import { checkOnboardingStatus } from '../libs/onboarding';
@@ -194,14 +196,14 @@ function _lastHistoryEntryWasToday (lastHistoryEntry, user) {
return false;
}
const { timezoneOffset } = user.preferences;
const timezoneUtcOffset = getUtcOffset(user);
const { dayStart } = user.preferences;
// Adjust the last entry date according to the user's timezone and CDS
const dateWithTimeZone = moment(lastHistoryEntry.date).zone(timezoneOffset);
const dateWithTimeZone = moment(lastHistoryEntry.date).utcOffset(timezoneUtcOffset);
if (dateWithTimeZone.hour() < dayStart) dateWithTimeZone.subtract(1, 'day');
return moment().zone(timezoneOffset).isSame(dateWithTimeZone, 'day');
return moment().utcOffset(timezoneUtcOffset).isSame(dateWithTimeZone, 'day');
}
function _updateLastHistoryEntry (lastHistoryEntry, task, direction, times) {