[kaffe] Bug Report in GregorianCalendar.set or getMinimum
Christian Hammers
ch at lathspell.de
Tue Jul 16 13:56:21 PDT 2002
Hello
On Mon, Jul 15, 2002 at 01:59:08AM -0700, Dalibor Topic wrote:
> > GregorianCalendar is implemented unixtime based so
> > limited to 1970 - 2037.
> > But the actual bug is that getMinimum(Calendar.YEAR)
> > reports 0 as minimum,
> It seems that the error is introduced in
> computeFields, where the 1970 comes into play. Could
> you come up with a simple test case that triggers the
> bug?
It's simple:
$ cat YearBug.java
import java.util.*;
import java.text.*;
public class YearBug {
public static void main(String[] args) {
GregorianCalendar c0 = new GregorianCalendar( TimeZone.getTimeZone("UTC") );
c0.set(2002,07,06,15,00,00);
System.out.println(c0.getMinimum(Calendar.YEAR));
System.out.println(c0.getMaximum(Calendar.YEAR));
c0.set(1351,01,01,17,00,00);
c0.add(Calendar.YEAR,-100);
System.out.println(c0.get(Calendar.YEAR)+"\n"+c0);
}
}
$ kaffe YearBug
0
9999
1970
java.util.GregorianCalendar at 0
$ /opt/j2re1.4/bin/java YearBug
1
292278994
1251
java.util.GregorianCalendar[time=-22686073199178,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="UTC",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=1251,MONTH=1,WEEK_OF_YEAR=5,WEEK_OF_MONTH=1,DAY_OF_MONTH=1,DAY_OF_YEAR=32,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=5,HOUR_OF_DAY=17,MINUTE=0,SECOND=0,MILLISECOND=822,ZONE_OFFSET=0,DST_OFFSET=0]
[BTW: Let us fix the toString() first *g*]
> I think the best option would be to make it
> non-unixtime based, as otherwise the use of dates like
> GREGORIAN_CHANGE is limited.
Yes!
> Would you be interested in helping me fix those bugs, as you probably
> know more about Calendars than I do?
Oh, all I know about Calendars is what is written at
http://java.sun.com/j2se/1.4/docs/api/java/util/GregorianCalendar.html
although that is quite a lot. I feat I'm not as good as programmer to
do a cleanroom implementation of Suns classes but I can at least do some
regression testing to help you.
Perl has a nice package called Date::Calc. It's written in easy to read
C and perl and copes with dates from 0 to at least 3000. You might want to
use code from it.
ftp://ftp.cpan.org/pub/CPAN/modules/by-module/Date/Date-Calc-*.tar.gz
> dalibor topic
bye,
-christian-
More information about the kaffe
mailing list