Here's an excerpt of my test log:
[java] Weekly rules:
[java] Every week on Tuesday and Thursday:
[java] FREQ=WEEKLY;BYDAY=TU,TH
[java] All occurrences:
[java] 1) Tue Sep 16 14:29:45 EEST 2003
[java] 2) Thu Sep 18 14:29:45 EEST 2003
...
[java] 31) Tue Dec 30 14:29:45 EET 2003
[java] 32) Tue Jan 06 14:29:45 EET 2004
[java] 33) Thu Jan 08 14:29:45 EET 2004
[java] 34) Tue Jan 13 14:29:45 EET 2004
...
Occurrence number 32 should be "Thu, Jan 01, 14:29:45
EET 2004".
I traced this bug a bit, and spotted the cause of the
error in the method "private HashSet
breedWeekDayMetaSet(HashSet origSet , HashSet
metaSet)" in RecurranceRuleRfc class. The following
condition causes this problem:
if ( hunter.get(Calendar.YEAR) == curProtoDate.get
(Calendar.YEAR) )
When the hunter variable points to 01-Jan-2004, the
curProtoDate points to year 2003. Therefore, the date
01-Jan-2004 is never added to the result set.
First, I tried to remove the error by commenting the
condition. However, this caused a significant
performance loss, so I decided to introduce a new helper
method "within7Days(Calendar c1, Calendar c2)" and
modified the condition to be like this:
if ( within7Days(hunter, curProtoDate) || hunter.get
(Calendar.YEAR) == curProtoDate.get(Calendar.YEAR) ){
This "dirty hack" seemed to do the trick, and did not
cause any notable performance loss compared to the
original version. Here's the output after running the test
again:
[java] Weekly rules:
[java] Every week on Tuesday and Thursday:
[java] FREQ=WEEKLY;BYDAY=TU,TH
[java] All occurrences:
[java] 1) Tue Sep 16 14:29:45 EEST 2003
[java] 2) Thu Sep 18 14:29:45 EEST 2003
...
[java] 31) Tue Dec 30 14:29:45 EET 2003
[java] 32) Thu Jan 01 14:29:45 EET 2004
[java] 33) Tue Jan 06 14:29:45 EET 2004
[java] 34) Thu Jan 08 14:29:45 EET 2004
[java] 35) Tue Jan 13 14:29:45 EET 2004
Do you think that such a modification can break
something else in the code?
Nobody/Anonymous
None
None
Public
Copyright © 2009 Geeknet, Inc. All rights reserved. Terms of Use