Jacob said:
Cid wrote:
I wrote a simple day class making a *date* front-end to
a calendar object, and including all common operations
(and no uncommon
See
http://geosoft.no/software/day/Day.java.html
It's too simple. It contains a bug!
I added the following code to the bottom of your main()
in order to show the number of days between April 1 of
this year and various other days in the same month.
Day oneDay = new Day( 2004, Calendar.APRIL, 1 );
for ( int i = 1; i < 6; i++ ) {
Day anotherDay = new Day( 2004, Calendar.APRIL, i );
System.out.println( "April " + i + " - April 1 = " +
oneDay.daysBetween(anotherDay));
}
Results in:
912
1037
7
April 1 - April 1 = 0
April 2 - April 1 = 1
April 3 - April 1 = 2
April 4 - April 1 = 2
April 5 - April 1 = 3
Both April 3 and April 4 being 2 days from April 1 and all later
days are off by one.
What's with that? Because in my local timezone April 4th is 23 hours long
since it is the 'Spring Forward' DLS date.
A quick fix is to add 1 hour before rounding, because I believe you
are always trying to work with 12 Midnight days. Another fix would be
to create (clone?) Calendars using an explicit GMT (with no DLS switching).
FWIW, the other test cases shown are not effected by this calculation since
the contain pairs of 23 and 25 hour days.
Daylight savings is such a pain!
HTH,
-Paul
p.s. copies of this message direct to the poster and for the record on the
newsgroup since the code from his site which others may have downloaded
contains a bug.