Bug-fix to date formatting

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

Bug-fix to date formatting

Post by Ian Mayo » Fri Jan 11, 2002 8:41 am

Hi,
I'm really impressed with the algorithm you use for producing tick-marks and labels in a time-series.

I encountered a bug where ticks weren't produced when the tick-units shrunk to milliseconds. The bug was in a clever-looking case statement in the previousStandardDate method in DateAxis:


case(Calendar.MILLISECOND) : {
calendar.set(Calendar.MILLISECOND, value);
}

This statement set the correct number of milliseconds, and didn't RETURN, but let the SECONDS case get handled. Unfortuntely the SECONDS case over-wrote the milliseconds, as well as setting the wrong number of seconds. Accordingly this case statement should be:

case(Calendar.MILLISECOND) : {
years = calendar.get(Calendar.YEAR);
months = calendar.get(Calendar.MONTH);
days = calendar.get(Calendar.DATE);
hours = calendar.get(Calendar.HOUR_OF_DAY);
minutes = calendar.get(Calendar.MINUTE);
seconds = calendar.get(Calendar.SECOND);
calendar.set(years, months, days, hours, minutes, seconds);
calendar.set(Calendar.MILLISECOND, value);
return calendar.getTime();
}

It all works fine now.

Congrats on the application,

Ian

David Gilbert

RE: Bug-fix to date formatting

Post by David Gilbert » Mon Jan 14, 2002 8:47 am

Thanks Ian, well spotted. I've made the change, so it will be fixed in the next version.

DG.

Locked