Hi,
I'm trying to add data to a TimeSeries object, using the Second class for the period. However I get this exception:
Exception in thread "AWT-EventQueue-0" org.jfree.data.general.SeriesException: You are attempting to add an observation for the time period Sun Apr 05 02:00:00 EST 2009 but the series already contains an observation for that time period. Duplicates are not permitted. Try using the addOrUpdate() method.
This happens when I have two data items from the Daylight Savings Time change over point for the default timezone. So for instance I would have Sun Apr 05 02:00:00 EST 2009 twice because this is when daylight savings time ends in Australia and so 2:00 occurs twice on this date. I have tried setting the Second to a non-dst affected timezone but this doesn't seem to change anything, it still seems to use the default timezone and TimeSeries doesn't seem to have a TimeZone setting. I'm using version 1.0.13 of JfreeChart and JDK 1.6.
DST Time Series Duplicate
Re: DST Time Series Duplicate
Hi Alex,
I had a similar problem, and I no longer do.
1) I am using FixedMillisecond instead of Second.
2) I have an XML layer which converts Dates to strings via SimpleDateFormat, and then back to Dates again from the XML in the rendering layer. With many format strings, the conversion is not safe at the daylight savings boundaries and the conversion itself produced duplicate Dates. I found that using the simplest 'Z' version for the timezone information in the format string cured this.
I am not sure if 1). is required, or if you might be doing something similar to 2), or if you've found a bug in JFreeChart or Java that is similar in nature to 2).
I hope this information helps, and good luck.
-Jonathan
3) I also seem to remember having some weirdness caused by my code calling Timezone.setDefault(), changing the default timezone after JFreeChart had already been invoked once. I can't remember the exact problem or its symptoms but at the time I came to the conclusion that it wasn't a safe thing to do and made sure to stop doing it.
I had a similar problem, and I no longer do.
1) I am using FixedMillisecond instead of Second.
2) I have an XML layer which converts Dates to strings via SimpleDateFormat, and then back to Dates again from the XML in the rendering layer. With many format strings, the conversion is not safe at the daylight savings boundaries and the conversion itself produced duplicate Dates. I found that using the simplest 'Z' version for the timezone information in the format string cured this.
I am not sure if 1). is required, or if you might be doing something similar to 2), or if you've found a bug in JFreeChart or Java that is similar in nature to 2).
I hope this information helps, and good luck.
-Jonathan
3) I also seem to remember having some weirdness caused by my code calling Timezone.setDefault(), changing the default timezone after JFreeChart had already been invoked once. I can't remember the exact problem or its symptoms but at the time I came to the conclusion that it wasn't a safe thing to do and made sure to stop doing it.
Re: DST Time Series Duplicate
Part of the problem is that you cannot use EST to define the timezone because it is ambiguous. I know you meant Australia Eastern Standard Time, but EST also refers to USA Eastern Standard Time. (This is mentioned in the javadoc for java.util.TimeZone)AlexTG wrote:Hi,
I'm trying to add data to a TimeSeries object, using the Second class for the period. However I get this exception:
Exception in thread "AWT-EventQueue-0" org.jfree.data.general.SeriesException: You are attempting to add an observation for the time period Sun Apr 05 02:00:00 EST 2009 but the series already contains an observation for that time period. Duplicates are not permitted. Try using the addOrUpdate() method.
This happens when I have two data items from the Daylight Savings Time change over point for the default timezone. So for instance I would have Sun Apr 05 02:00:00 EST 2009 twice because this is when daylight savings time ends in Australia and so 2:00 occurs twice on this date. I have tried setting the Second to a non-dst affected timezone but this doesn't seem to change anything, it still seems to use the default timezone and TimeSeries doesn't seem to have a TimeZone setting. I'm using version 1.0.13 of JfreeChart and JDK 1.6.
To avoid this problem you should always use the long format like
Code: Select all
TimeZone tz = TimeZone.getTimeZone("Australia/Sydney");
Code: Select all
Second(java.util.Date time, java.util.TimeZone zone)
Re: DST Time Series Duplicate
Oh... actually my bad, turns out setting the Second to a a non-DST timezone does work, not sure why I thought it didn't. I think I might have gotten confused by the fact that when you call toString() on a Second it displays using the default timezone rather than the timezone of the Second.
Second s = new Second(date,TimeZone.getTimeZone("Etc/UTC"),Locale.ENGLISH) = good.
Thanks for the pointers guys.
Second s = new Second(date,TimeZone.getTimeZone("Etc/UTC"),Locale.ENGLISH) = good.
Thanks for the pointers guys.