mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
Repeatables fixes (#8538)
* Prevented watch functions from being called when task._edit is removed * Added start date support on the UI task summary * Fixed setting of monthly and calculations * Fixed linting issues * Added check for existence * Added existence check * Ensured correct start date is used on update * Hid repeat options from anything not a daily * Added missing locales * Moved repeatables out of advance options
This commit is contained in:
@@ -97,6 +97,9 @@ export function shouldDo (day, dailyTask) {
|
||||
return false;
|
||||
}
|
||||
|
||||
day = moment(day).startOf('day').toDate();
|
||||
let startDate = moment(dailyTask.startDate).startOf('day').toDate();
|
||||
|
||||
let daysOfTheWeek = [];
|
||||
|
||||
if (dailyTask.repeat) {
|
||||
@@ -105,14 +108,13 @@ export function shouldDo (day, dailyTask) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (dailyTask.frequency === 'daily') {
|
||||
if (!dailyTask.everyX) return false; // error condition
|
||||
let schedule = moment(dailyTask.startDate).recur()
|
||||
let schedule = moment(startDate).recur()
|
||||
.every(dailyTask.everyX).days();
|
||||
return schedule.matches(day);
|
||||
} else if (dailyTask.frequency === 'weekly') {
|
||||
let schedule = moment(dailyTask.startDate).recur();
|
||||
let schedule = moment(startDate).recur();
|
||||
|
||||
if (dailyTask.everyX > 1) {
|
||||
schedule = schedule.every(dailyTask.everyX).weeks();
|
||||
@@ -122,21 +124,21 @@ export function shouldDo (day, dailyTask) {
|
||||
|
||||
return schedule.matches(day);
|
||||
} else if (dailyTask.frequency === 'monthly') {
|
||||
let schedule = moment(dailyTask.startDate).recur();
|
||||
let schedule = moment(startDate).recur();
|
||||
|
||||
let differenceInMonths = moment(day).month() + 1 - moment(dailyTask.startDate).month() + 1;
|
||||
let differenceInMonths = moment(day).month() + 1 - moment(startDate).month() + 1;
|
||||
let matchEveryX = differenceInMonths % dailyTask.everyX === 0;
|
||||
|
||||
if (dailyTask.weeksOfMonth) {
|
||||
if (dailyTask.weeksOfMonth && dailyTask.weeksOfMonth.length > 0) {
|
||||
schedule = schedule.every(daysOfTheWeek).daysOfWeek()
|
||||
.every(dailyTask.weeksOfMonth).weeksOfMonthByDay();
|
||||
} else if (dailyTask.daysOfMonth) {
|
||||
} else if (dailyTask.daysOfMonth && dailyTask.daysOfMonth.length > 0) {
|
||||
schedule = schedule.every(dailyTask.daysOfMonth).daysOfMonth();
|
||||
}
|
||||
|
||||
return schedule.matches(day) && matchEveryX;
|
||||
} else if (dailyTask.frequency === 'yearly') {
|
||||
let schedule = moment(dailyTask.startDate).recur();
|
||||
let schedule = moment(startDate).recur();
|
||||
|
||||
schedule = schedule.every(dailyTask.everyX).years();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user