When you create a Daily that has a monthly repeat with the "Day of the Month" setting, the day (the daysOfMonth value) is taken from the Start Date - e.g., if you create the Daily on the 15th of the month, then daysOfMonth is set to [ 15 ] and the Daily repeats on the 15th of every month. That works corectly.
However if you change the Start Date to make the Daily repeat on a different day, the daysOfMonth value is not updated so the Daily is still due on the 15th.
A workaround is to change the "Day of the Month" setting to "Day of the Week", save it, then edit the Daily again to change it back. The daysOfMonth setting is then correctly set to the day taken from the Start Date.
Here's an example of a Daily that has this bug, before the fix was applied:
{
"_id": "34395d2f-feac-46f1-a7a5-e77a2fd30942",
"isDue": true,
"userId": "dea8a9e8-c084-438a-9a14-7fe96a73fd0a",
"text": "xxxxxxxx",
"updatedAt": "2017-10-15T19:05:59.011Z",
"createdAt": "2017-05-25T16:00:41.942Z",
"reminders": [],
"group": { "approval": { "requested": false, "approved": false, "required": false }, "assignedUsers": [] },
"challenge": {},
"attribute": "con",
"priority": 1.5,
"value": 21.78349273965064,
"tags": [ "5840ac40-194d-4202-b7fd-08f061d5bcab" ],
"notes": "xxxxxxxx",
"type": "daily",
"checklist": [
],
"collapseChecklist": false,
"completed": false,
"history": [ snipped ],
"nextDue": [
"2017-11-01T04:00:00.000Z",
"2017-12-01T04:00:00.000Z",
"2018-01-01T04:00:00.000Z",
"2018-02-01T04:00:00.000Z",
"2018-03-01T04:00:00.000Z",
"2018-04-01T04:00:00.000Z"
],
"weeksOfMonth": [],
"daysOfMonth": [
15
],
"streak": 6,
"repeat": {
"su": true,
"s": true,
"f": true,
"th": true,
"w": true,
"t": true,
"m": true
},
"startDate": "2017-10-01T19:04:00.000Z",
"everyX": 1,
"frequency": "monthly",
"__v": 124,
"yesterDaily": true
}
I can take a look at this one
@abatula Thank you!
Same happens with the "repeat after xx days" in the daily setting. The workaround works fine: I switched to weekly setting saving the task, and then back to daily setting and it was solved.
@abatula How are you going with this fix? Do you need any help?
Aahh, sorry, I didn't realize how long it had been! I'm hoping to have more time to dig into this after Thanksgiving weekend (US). But also yes, I haven't been able to figure out where thing are being set for dailies, I wanted to is that as a starting point.
I took another look at the files, and I still can't find where daysOfMonth is set at all (or daysOfWeek, which I tried to find for comparison). The most promising code I found was in website/client/components/tasks/taskModal.vue, but even then I don't see when/how the set function is called, or exactly what it does.
@abatula I think the code you're searching for is in taskModal.vue indeed, under the repeatsOn computed property:
repeatsOn: {
get () {
let repeatsOn = 'dayOfMonth';
if (this.task.type === 'daily' && this.task.weeksOfMonth && this.task.weeksOfMonth.length > 0) {
repeatsOn = 'dayOfWeek';
}
return repeatsOn;
},
set (newValue) {
const task = this.task;
if (task.frequency === 'monthly' && newValue === 'dayOfMonth') {
const date = moment(task.startDate).date();
task.weeksOfMonth = [];
task.daysOfMonth = [date];
} else if (task.frequency === 'monthly' && newValue === 'dayOfWeek') {
const week = Math.ceil(moment(task.startDate).date() / 7) - 1;
const dayOfWeek = moment(task.startDate).day();
const shortDay = this.dayMapping[dayOfWeek];
task.daysOfMonth = [];
task.weeksOfMonth = [week];
for (let key in task.repeat) {
task.repeat[key] = false;
}
task.repeat[shortDay] = true;
}
},
},
You can learn how that works here https://vuejs.org/v2/guide/computed.html
I think I figured out the problem, but I'm not sure how to fix it. It seems that set (newValue) is only called when the toggle button for day of month/day of week in the task edit window is changed, but isn't called when left at the default value (which happens to be daysOfMonth). So when creating a task, clicking the radial for day of week and then immediately back to day of month causes the set method to be called, and it all works properly.
So, the logic in set needs to be run whenever anything is changed (e.g. if the start date is changed on an existing monthly we need to make sure it's called again) or a new task is created, not just when the the radio button value is changed. But I'm not sure how to do that.
@abatula are you still working on this?
@Hus274 No, I've taken this one as far as I can. If you want to work on it, it's all yours!
Posted a pull request. Should be able to move to status: issue: in progress
Reopening. PR #10095 is live in production, but the fix is incomplete. The first time you set a Daily to have a monthly schedule, the daysOfMonth field does not get updated. You need to reopen the Daily and save it a second time for it to take. @Hus274 any thoughts?
Can you provide the steps to replicate? I just tried it on my main account and wasn't able to replicate the issue.
As a note, you need to click save after modifying the date, not click off the modal. That's the only other thing I can think of.
@Hus274
frequency: monthly but an empty array in daysOfMonth.daysOfMonth has a value.Got it now, thanks. Let me take a look
I believe I've fixed the issue, posted a new pull request with the changes here.
Closing since the commit that fixes this has been committed to release