Poss. bug in BasicTimeSeries

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

Poss. bug in BasicTimeSeries

Post by Trevor Hills » Thu Jan 24, 2002 3:33 am

I have code something like the following:

BasicTimeSeries timeSeries = new BasicTimeSeries("Series Name");
while(dataKeys.hasMoreElements()){
thisKey = dataKeys.nextElement();
thisDate = (String)thisKey;
day = Integer.valueOf(thisDate.substring(8,10)).intValue();
month = Integer.valueOf(thisDate.substring(5,7)).intValue();
year = Integer.valueOf(thisDate.substring(0,4)).intValue();
try {
timeSeries.add(new Day(day, month, year), Double.valueOf(graphData.get(thisKey).toString()));
} catch (Exception e){
System.out.println("Error adding date, Day: " + day + " Month: " + month + " Year: " + year);
e.printStackTrace();
}
} //end while

Where dataKeys is a string of the format "YYYY-MM-dd". I have a range of dates from 1999-01-01 to 2002-01-01 and it happily plunks these values in, all but for the 2000-03-01, that is 01-mar-2000. For this date I get the error:

Error adding date, Day: 1 Month: 3 Year: 2000
com.jrefinery.data.SeriesException: TimeSeries.add(...): time period already exists.
at com.jrefinery.data.BasicTimeSeries.add(Unknown Source)
at com.jrefinery.data.BasicTimeSeries.add(Unknown Source)
at com.pavtech.prs.MilkReport.createTimeSeriesData(MilkReport.java:282)
at com.pavtech.prs.MilkReport.drawLineChart(MilkReport.java:309)
at com.pavtech.prs.MilkReport.doGet(MilkReport.java:104)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
at org.apache.tomcat.core.Handler.service(Handler.java:287)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:806)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:752)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
at java.lang.Thread.run(Thread.java:484)

I have very carefully checked my data set and there is no duplication. Now, 2000 was a leap year but is not detected by the standard formula "A leap year occurs on every year that is evenly divisible by four. Unless: If the year is also divisible by 100, it is not a leap year." but it is if you add the complete definition, namely " Unless: If the year is evenly divisible by 100 AND by 400, it is a leap year." I think the issue may have it roots in this common mistake.

David Gilbert

Confirmed and fixed

Post by David Gilbert » Thu Jan 24, 2002 11:27 am

Hi Trevor,

Thanks for the bug report. To fix it you need to modify a line in the calcSerial(...) method in the SpreadsheetDate class in the JCommon class library. The line that says:

if (m>SerialDate.FEBRUARY) {

should read:

if (month>SerialDate.FEBRUARY) {

The effect of the bug is to offset by 1 the serial number used to represent the date for any date in February of any leap year...which of course is a bad thing.

Thanks again for the report...

DG.

Locked