[kaffe] GregorianCalendar bug?

Helmer Krämer hkraemer at freenet.de
Fri Oct 11 06:26:49 PDT 2002


Hi all,

while trying to get Tomcat 4.0.4 to run with kaffe CVS,
I stumbled across the following line in GregorianCalendar.java:

int wday = up ? (int)((EPOCH_WDAY + days + 1) % DAYSPERWEEK) : (int)(((EPOCH_WDAY - days + 1) % DAYSPERWEEK) + DAYSPERWEEK);

which is supposed to calculate the day of the week (up is true
when calculating something after 1.1. 1970, otherwise false).

I think this should be something like this:

int wday = up ? (int)((EPOCH_WDAY + days) % DAYSPERWEEK + 1) : (int)(((EPOCH_WDAY - days) % DAYSPERWEEK + 1));

because adding 1 before doing the modulo gives incorrect results for
saturdays (for saturdays EPOCH_WDAY+days will be 6, so wday will be
0, which isn't a valid constant for a weekday) and adding DAYSPERWEEK
simply can't be right, because it will always give results that are
bigger than 7.


Greetings,
Helmer




More information about the kaffe mailing list