JCommon 5.6 Day Bug in getStart()

A discussion forum for the JCommon class library.
Locked
Elijah C. Menifee

JCommon 5.6 Day Bug in getStart()

Post by Elijah C. Menifee » Fri Mar 15, 2002 9:38 pm

Using the following code one would expect to get The equivlent Date object out as used
to construct the Day Object

public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss.SSS");
Date date = new Date(2002-1900,2,15);
Day day1 = new Day(date);
long day1start = day1.getStart();
long diff = date.getTime() - day1start;
System.out.println("date date: " + sdf.format(new Date(date.getTime())));
System.out.println("data day1: " + sdf.format(new Date(day1start)));
System.out.println("datelong: " + date.getTime());
System.out.println("day1long: " + day1start);
System.out.println("longdiff: " + diff);
System.out.println("timediff: " + diff/3600000 + ":" + (diff%3600000)/60000 + " " + (diff%60000)/1000 + "." + diff%1000);
}

however the output produces:
in constructor by date: 2002-3-15
date date: 03-15-2002 00:00:00.000
data day1: 03-14-2002 12:00:00.001
datelong: 1016172000000
day1long: 1016128800001
longdiff: 43199999
timediff: 11:59 59.999


By changing:
public long getStart(int offset) {
return (serialDate.toSerial() -JAVA_DATE_EPOCH) *MILLISECONDS_PER_DAY +offset+1;
}

to:
public long getStart(int offset) {
return (serialDate.toSerial() -JAVA_DATE_EPOCH)* MILLISECONDS_PER_DAY -offset;
}

I get the output I expect which is:

in constructor by date: 2002-3-15
date date: 03-15-2002 00:00:00.000
data day1: 03-15-2002 00:00:00.000
datelong: 1016172000000
day1long: 1016172000000
longdiff: 0
timediff: 0:0 0.0

Have not tested or attempted to fix getEnd, leaving as excersise to the Reader ( aka the author)

David Gilbert

Re: JCommon 5.6 Day Bug in getStart()

Post by David Gilbert » Mon Mar 18, 2002 10:19 am

Thanks for reporting this. I will have it fixed for the next release.

Regards,

Dave Gilbert

Locked