Skip to content
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

RecurrenceRule returns wrong BYMONTH part value #98

Open
yermolovich1987 opened this issue Jul 2, 2021 · 4 comments
Open

RecurrenceRule returns wrong BYMONTH part value #98

yermolovich1987 opened this issue Jul 2, 2021 · 4 comments

Comments

@yermolovich1987
Copy link

Hi all. Recently I have found a strange behaviour that seems like a bug. When we build a RecurrentRule with BYMONTH part and then try to get the value of BYMONTH part from the result object via rule.getByPart(RecurrenceRule.Part.BYMONTH) - it returns the values that are reduced on 1. At the same time, if we will try to convert the object back to the RRULE string or calculate the next occurrence date - all is working correctly. As I can see, this happens because when GregorianCalendarMetrics parses BYMONTH for internal purposes it decrease the month and then increase back during serialization back to String. At the same time, from API point of view this seems confusing since I expect to receive always the correct values - both when get a particular part via direct method call or when convert to result String.
The sample code to demonstrate the issue:

var ruleToTest = "FREQ=WEEKLY;BYMONTH=11;COUNT=1"; 
var rule = new RecurrenceRule(ruleToTest);
var iterator = rule.iterator(DateTime.parse("20210701T120000Z"));
System.out.println(iterator.nextDateTime());
System.out.println(rule.getByPart(RecurrenceRule.Part.BYMONTH));
System.out.println(rule.toString());

The output will look like:

20211104T120000Z
[10]
FREQ=WEEKLY;BYMONTH=11;COUNT=1

As you can see, the calculated next date and the RRULE string contains the correct month - 11. But the rule.getByPart(RecurrenceRule.Part.BYMONTH) returns the value 10.

Is this an intended behaviour and is there any proper way to receive the correct value of the BYMONTH part?
Thanks!

@dmfs
Copy link
Owner

dmfs commented Jul 4, 2021

Right, sounds like a bug indeed. Shouldn't be hard to fix though. I'll check that.

@dmfs
Copy link
Owner

dmfs commented Jul 4, 2021

After looking into the code again, it realized this was actually intended behaviour. RFC 5545 (and therefore RRULE) use 1-based month numbers, whereas Java's Calendar class (which served as the model for the implementation back then, when I started this) uses 0-based month numbers.
IIRC, the idea was to separate String representation and API, just like the Calendar class does. So to retrieve the actual month number you have to add 1. For calendars which have leap months it would be more difficult though, but that's not supported yet. I guess the API needs to be reworked a bit.

@yermolovich1987
Copy link
Author

Hi Marten. Thanks for response and for library! I think that you are right and in that case better to update an API so that rule.getByPart(RecurrenceRule.Part.BYMONTH) returns the same month number as configured in the original rule/string representation.

@GoldenSoju
Copy link

Hi all~!
I was wondering if there are any updates on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants