Basic Bug in Mintute Date functions?
Basic Bug in Mintute Date functions?
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
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
Re: Basic Bug in Mintute Date functions?
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
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
Re: Basic Bug in Mintute Date functions?
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
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
Re: Basic Bug in Mintute Date functions?
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.
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.
Re: Basic Bug in Mintute Date functions?
Use Milliseciond. It is different from Minute, and the timezones seem to work.
Re: Basic Bug in Mintute Date functions?
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
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
Re: Basic Bug in Minute Date functions?
Ooops! Thanks for the report, I'll fix it.
DG.
DG.
Re: Basic Bug in Mintute Date functions?
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
java.util.TimeZone.setDefault(java.util.TimeZone.getTimeZone("UTC"));
Have it somewhere in your main method, the earlier, the better.
Greetings, GreGie