-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong first occurrence for Monthly rule with BYMONTHDAY in particular cases #232
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I apologize for the long delay! I have some comments that I hope we didn't already discuss in a Mozilla bug. Let me know what you think!
lib/ical/recur_iterator.js
Outdated
this.last.month = this.setup_defaults("BYMONTH", "MONTHLY", this.dtstart.month); | ||
var daysInMonth = ICAL.Time.daysInMonth(this.last.month, this.last.year); | ||
while (Math.abs(day) > daysInMonth) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if someone wrongly specifies BYMONTHDAY=32 ? Would this be caught somewhere else or would the loop keep spinning? Maybe you could add a test for this too.
lib/ical/recur_iterator.js
Outdated
daysInMonth = ICAL.Time.daysInMonth(this.last.month, this.last.year); | ||
} | ||
if (day < 0) { | ||
day = daysInMonth + day + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
day += daysInMonth + 1
lib/ical/recur_iterator.js
Outdated
} | ||
|
||
if (day > daysInMonth) { | ||
this.last.day = 1; | ||
data_valid = this.is_day_in_byday(this.last); | ||
} else { | ||
} else if (day > 0) { | ||
this.last.day = day; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a possibility for an else case? If so there should be some sort of fallback.
@Decathlon1578 I would like to continue working on your pull request, can you enable edits from maintainers for it? Then I can directly push an update to your branch and pull request. |
@mschroeder A simply fix might be done simply by adding a counter in the patch's |while| loop. Even if it's a bit rough, it would throw an error and would keep Lightning functioning . I have to add some tests for these kind of rules and I'm going to upload a new patch. |
8e9f69e
to
434b444
Compare
After a long fight with GIT (now I'm in the long list of the git heaters) I thought that everything was fine, I'm going to squash the commits relatively to the patch after the review, but now there's a problem with the "grunt package" command. |
Most of the time this happens if you have not installed the same versions of npm packages as Travis CI. To ensure this, delete the node_modules directory and run |
1e93f1b
to
147b97e
Compare
147b97e
to
b0db4e3
Compare
7a84450
to
5079ddf
Compare
OK, I'm a bit tired so I surrender.
I deleted the file package-lock.json (438KB) before the "grunt package" command in order to avoid to commit it because it doesn't exist upstream. I don't know what I have to do to make it working. Given that the patch works, and passes all the tests included the new ones, if someone else want to complete the work, I've activate the flag "Allow edits from maintainers". Well, maybe I'll activate the flag because now GitHub complains, with a big red message, that I can't do that action in this moment. About the fix, I've added tests for the case BYMONTHDAY>31 that is treated by the rule parser. Moreover, as I mentioned in the above answer to mschroeder, I've added a counter that allows to catch those condictions that hangs the code and cause global dataloss when the BYMONTHDAY doesn't exist for a given BYMONTH (e.g. the 31st in April) and added related tests. |
@Decathlon1578, can you try to set the flag "Allow edits from maintainers" again, please? |
@mschroeder maybe you want to just open a new PR and we'll close this one? |
Opened new PR #418 as suggested. |
This PR covers issues which occurs with monthly rules with BYMONTHDAY.
The first occurrence is not always calculated correctly when the BYMONTHDAY, as absolute value, is greater than the last day of the month where the event starts or the last day of the month where the occurrence should occur in case of INTERVAL in the rule.
Mainly the issues are described in Lightning's bugs:
https://bugzilla.mozilla.org/show_bug.cgi?id=1266797
https://bugzilla.mozilla.org/show_bug.cgi?id=386516#c11