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!
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:
The output will look like:
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!