9:15, 9:30, 9:45, and so on
With 1.0.4 and 1.0.5 the result is now different:
9:14, 9:29, 9:44, ...
So, as you see there's a delay of minute in the position where the label should be get.
I've been investigating the source code and I found the place that causes that:
In DataAxis.java:
Code: Select all
protected Date previousStandardDate(Date date, DateTickUnit unit) {
int milliseconds;
int seconds;
int minutes;
int hours;
int days;
int months;
int years;
Calendar calendar = Calendar.getInstance(getTimeZone());
calendar.setTime(date);
int count = unit.getCount();
int current = calendar.get(unit.getCalendarField());
int value = count * (current / count);
switch (unit.getUnit()) {
case (DateTickUnit.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();
case (DateTickUnit.SECOND) :
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);
if (getTickMarkPosition() == DateTickMarkPosition.START) {
milliseconds = 0;
}
else if (getTickMarkPosition() == DateTickMarkPosition.MIDDLE) {
milliseconds = 500;
}
else {
milliseconds = 999;
}
calendar.set(Calendar.MILLISECOND, milliseconds);
calendar.set(years, months, days, hours, minutes, value);
return calendar.getTime();
case (DateTickUnit.MINUTE) :
years = calendar.get(Calendar.YEAR);
months = calendar.get(Calendar.MONTH);
days = calendar.get(Calendar.DATE);
hours = calendar.get(Calendar.HOUR_OF_DAY);
if (getTickMarkPosition() == DateTickMarkPosition.START) {
seconds = 0;
}
else if (getTickMarkPosition() == DateTickMarkPosition.MIDDLE) {
seconds = 30;
}
else {
seconds = 59;
}
calendar.clear(Calendar.MILLISECOND);
calendar.set(years, months, days, hours, value, seconds);
Date d0 = calendar.getTime();
if (d0.getTime() >= date.getTime()) {
calendar.set(Calendar.MINUTE, value - 1);
d0 = calendar.getTime();
}
return d0;
case (DateTickUnit.HOUR) :
years = calendar.get(Calendar.YEAR);
months = calendar.get(Calendar.MONTH);
days = calendar.get(Calendar.DATE);
if (getTickMarkPosition() == DateTickMarkPosition.START) {
minutes = 0;
seconds = 0;
}
else if (getTickMarkPosition() == DateTickMarkPosition.MIDDLE) {
minutes = 30;
seconds = 0;
}
else {
minutes = 59;
seconds = 59;
}
calendar.clear(Calendar.MILLISECOND);
calendar.set(years, months, days, value, minutes, seconds);
Date d1 = calendar.getTime();
if (d1.getTime() >= date.getTime()) {
calendar.set(Calendar.HOUR_OF_DAY, value - 1);
d1 = calendar.getTime();
}
return d1;
case (DateTickUnit.DAY) :
years = calendar.get(Calendar.YEAR);
months = calendar.get(Calendar.MONTH);
if (getTickMarkPosition() == DateTickMarkPosition.START) {
hours = 0;
minutes = 0;
seconds = 0;
}
else if (getTickMarkPosition() == DateTickMarkPosition.MIDDLE) {
hours = 12;
minutes = 0;
seconds = 0;
}
else {
hours = 23;
minutes = 59;
seconds = 59;
}
calendar.clear(Calendar.MILLISECOND);
calendar.set(years, months, value, hours, 0, 0);
// long result = calendar.getTimeInMillis();
// won't work with JDK 1.3
Date d2 = calendar.getTime();
if (d2.getTime() >= date.getTime()) {
calendar.set(Calendar.DATE, value - 1);
d2 = calendar.getTime();
}
return d2;
case (DateTickUnit.MONTH) :
years = calendar.get(Calendar.YEAR);
calendar.clear(Calendar.MILLISECOND);
calendar.set(years, value, 1, 0, 0, 0);
Month month = new Month(calendar.getTime());
Date standardDate = calculateDateForPosition(
month, getTickMarkPosition());
long millis = standardDate.getTime();
if (millis > date.getTime()) {
month = (Month) month.previous();
standardDate = calculateDateForPosition(
month, getTickMarkPosition());
}
return standardDate;
case(DateTickUnit.YEAR) :
if (getTickMarkPosition() == DateTickMarkPosition.START) {
months = 0;
days = 1;
}
else if (getTickMarkPosition() == DateTickMarkPosition.MIDDLE) {
months = 6;
days = 1;
}
else {
months = 11;
days = 31;
}
calendar.clear(Calendar.MILLISECOND);
calendar.set(value, months, days, 0, 0, 0);
Date d3 = calendar.getTime();
if (d3.getTime() >= date.getTime()) {
calendar.set(Calendar.YEAR, value - 1);
d3 = calendar.getTime();
}
return d3;
default: return null;
}
Code: Select all
case (DateTickUnit.MINUTE) :
years = calendar.get(Calendar.YEAR);
months = calendar.get(Calendar.MONTH);
days = calendar.get(Calendar.DATE);
hours = calendar.get(Calendar.HOUR_OF_DAY);
if (getTickMarkPosition() == DateTickMarkPosition.START) {
seconds = 0;
}
else if (getTickMarkPosition() == DateTickMarkPosition.MIDDLE) {
seconds = 30;
}
else {
seconds = 59;
}
calendar.clear(Calendar.MILLISECOND);
calendar.set(years, months, days, hours, value, seconds);
Date d0 = calendar.getTime();
if (d0.getTime() >= date.getTime()) {
calendar.set(Calendar.MINUTE, value - 1);
d0 = calendar.getTime();
}
return d0;
So if I replace:
Code: Select all
if (d0.getTime() >= date.getTime()) {
calendar.set(Calendar.MINUTE, value - 1);
d0 = calendar.getTime();
}
Code: Select all
if (d0.getTime() > date.getTime()) {
calendar.set(Calendar.MINUTE, value - 1);
d0 = calendar.getTime();
}