Weekly/Monthly Habit reset counters resetting early - fixes #8570 (#8749)

* For habit reset logic, changed day check calculation to use user’s timezone instead of server time.
Added unit tests to check following cases:
- Weekly habit reset: Server tz is Sunday, User tz is Monday
- Weekly habit reset: Server tz is Monday, User tz is Sunday
- Monthly habit reset: Server tz is 1st of month, User tz is 2nd of month
- Monthly habit reset: Server tz is end of prev month, User tz is 1st of month

* use moment().zone() instead of utcOffset()

* typo

* Fixed check for daysMissed, added logic for CDS
Added test for CDS, fixed previous tests
This commit is contained in:
joe-salomon
2017-07-18 12:53:39 -07:00
committed by Sabe Jones
parent d822843bbf
commit cdbbf93b74
2 changed files with 165 additions and 4 deletions

View File

@@ -346,15 +346,15 @@ export function cron (options = {}) {
// check if we've passed a day on which we should reset the habit counters, including today
let resetWeekly = false;
let resetMonthly = false;
for (let i = 0; i <= daysMissed; i++) {
for (let i = 0; i < daysMissed; i++) {
if (resetWeekly === true && resetMonthly === true) {
break;
}
let thatDay = moment(now).subtract({days: i}).toDate();
if (thatDay.getDay() === 1) {
let thatDay = moment(now).zone(user.preferences.timezoneOffset + user.preferences.dayStart * 60).subtract({days: i});
if (thatDay.day() === 1) {
resetWeekly = true;
}
if (thatDay.getDate() === 1) {
if (thatDay.date() === 1) {
resetMonthly = true;
}
}