I've found a bug in DateAxis.previousStandardDate(Date, DateTickUnit). It returns wrong values in case the date given as parameter is already the standard date and the tick unit has a count > 1.
Testcase (DateAxis.previousStandardDate must be made public for this case):
Code: Select all
public static void main(String[] args)
{
Locale.setDefault(Locale.ENGLISH);
DateAxis da = new DateAxis();
DateFormat fDateShortTime = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
DateTickUnit tickUnit =
new DateTickUnit(DateTickUnitType.MINUTE, 30, DateTickUnitType.MINUTE, 5, fDateShortTime);
Date d = new Date(116,3,21,10,00,00);
for (int m = 0; m < 60; m++)
{
d.setMinutes(m);
Date dnext = da.previousStandardDate(d, tickUnit);
System.out.println("Input: "+fDateShortTime.format(d) + " Output: " + fDateShortTime.format(dnext));
}
}
Input: 2016-04-21 10:00 Output: 2016-04-21 09:59
Input: 2016-04-21 10:01 Output: 2016-04-21 10:00
Input: 2016-04-21 10:02 Output: 2016-04-21 10:00
Input: 2016-04-21 10:03 Output: 2016-04-21 10:00
...
Input: 2016-04-21 10:30 Output: 2016-04-21 10:29
Input: 2016-04-21 10:31 Output: 2016-04-21 10:30
Input: 2016-04-21 10:32 Output: 2016-04-21 10:30
Input: 2016-04-21 10:33 Output: 2016-04-21 10:30
...
There is an easy fix:
In DateAxis.previousStandardDate all occurrences of:
Code: Select all
if (dd.getTime() >= date.getTime()) {
calendar.set(Calendar.SECOND, value - 1);
dd = calendar.getTime();
}
Code: Select all
if (dd.getTime() >= date.getTime()) {
calendar.set(unit.getCalendarField(), value - count);
dd = calendar.getTime();
}
I don't have a GitHub account by hand. Maybe you can apply that yourself?
Thanks!!
Uli