Basic Bug in Mintute Date functions?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Anthony Berglas

Basic Bug in Mintute Date functions?

Post by Anthony Berglas » Tue Feb 12, 2002 4:15 am

There seems to be something very odd happening in the basic conversion between Java dates and JCommon dates. I think that this is the cause of wierd behaviour that we are getting in our charts. The following fragment demonstrates the problem -- what goes in does not come out!

I'm looking through the JCommon code, but all assistence welcome. JDK 1.3 Win NT.

Date date = new Date(102,2,11,18,4,19);
Day day = new Day(date.getDate(), // "Date" means Day of month, first day is 1
date.getMonth() +1, // January = 0 (!) so +1
date.getYear()+1900); // !!
int mins = date.getHours()*60 + date.getMinutes();
Minute min = new Minute(day, mins);
long ticks = min.getStart();
System.out.println("Date " + date + " Ticks " + date.getTime()+ " --> Minute(" + day + ", " + mins + ") --> ticks " + ticks + " Date " + new Date(ticks));
// Date Mon Mar 11 18:04:19 PST 2002 Ticks 1015898659000 --> Minute(11-March-2002, 1084) --> ticks 1015869780001 Date Mon Mar 11 10:03:00 PST 2002

Anthony Berglas

Re: Basic Bug in Mintute Date functions?

Post by Anthony Berglas » Tue Feb 12, 2002 8:32 pm

The following produces a more succinct example. The issue is wth Days and what Day.getStart means. Certainly it is incompatible with Java dates. Maybe timezone issue...

Anthony


Date date1 = new Date(102,1,11,18,4,19); // 11 Feb 2002 18:04:19
Day day1 = new Day(date1.getDate(), // "Date" means Day of month, first day is 1
date1.getMonth() +1, // January = 0 (!) so +1
date1.getYear()+1900); // !!
long ticks = day1.getStart();
System.out.println("Orig Date " + date1 + " Day " + day1 + " day Date " + new Date(ticks));
// Orig Date Mon Feb 11 18:04:19 PST 2002 Day 11-February-2002 day Date Sun Feb 10 16:00:00 PST 2002

Reji Mani

Re: Basic Bug in Mintute Date functions?

Post by Reji Mani » Wed Feb 13, 2002 2:11 am

Hi,

I am also facing the same problem. I am creating a BasicTimeSeries for Second.class . If we supply current Date object as TimePeriod, then chart shows 9 Hours forward. I think there is some bug in Date conversion or TimeZone. bcoz I am in GMT +9 Hrs timezone.

Any solutions for this....

Thanks in advance...

Reji from Korea

David Gilbert

Re: Basic Bug in Mintute Date functions?

Post by David Gilbert » Wed Feb 13, 2002 9:31 am

You are right it is a timezone issue.

Initially I wanted to create time series for annual, quarterly, monthly and daily data. Even for the daily data, the timezone isn't an issue for me. Then I thought why not make it more general and make it work with any time period, so I added Hour, Minute, Second and Millisecond. But I see now that these classes will need to take into account the timezone. So I'll have to look at it again...

Regards,

DG.

Anthony Berglas

Re: Basic Bug in Mintute Date functions?

Post by Anthony Berglas » Thu Mar 07, 2002 1:48 am

Use Milliseciond. It is different from Minute, and the timezones seem to work.

Dean Michaels

Re: Basic Bug in Mintute Date functions?

Post by Dean Michaels » Thu Mar 07, 2002 11:30 pm

CROSSPOST:

The amount of "drift" is double your local timezone offset from GMT.

It appears that it is a bug with com.jrefinery.data.TimeSeriesCollection.

/**
* Calculates the offset (in milliseconds) of the default time zone from GMT.
*/
private int calculateZoneOffset(Date time) {

TimeZone zone = TimeZone.getDefault();
int result = zone.getRawOffset();
if (zone.inDaylightTime(time)) {
result += 60*60*1000;
}
// return result; // the offset it the wrong way.
return (0-result) ; // return the negative value instead

}


This cleaned it up for me

David Gilbert

Re: Basic Bug in Minute Date functions?

Post by David Gilbert » Fri Mar 08, 2002 9:20 am

Ooops! Thanks for the report, I'll fix it.

DG.

GreGie

Re: Basic Bug in Mintute Date functions?

Post by GreGie » Thu Mar 14, 2002 4:11 pm

Another possibility is to fix the time zone to UTM (which means, no time zone issues whatsoever - everything you parse in and out is taken at face value):

java.util.TimeZone.setDefault(java.util.TimeZone.getTimeZone("UTC"));

Have it somewhere in your main method, the earlier, the better.

Greetings, GreGie

Locked