Fix within last year check in formatAbbrev
Previously this method considered a date within the last 365 days to be in the same year as today. Instead compare the actual years to avoid confusion. Fixes #3255.
This commit is contained in:
parent
082a452156
commit
24e4211da1
|
@ -7,6 +7,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.text.ParsePosition;
|
import java.text.ParsePosition;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -162,11 +163,10 @@ public class DateUtils {
|
||||||
if (date == null) {
|
if (date == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
GregorianCalendar now = new GregorianCalendar();
|
||||||
GregorianCalendar cal = new GregorianCalendar();
|
GregorianCalendar cal = new GregorianCalendar();
|
||||||
cal.add(GregorianCalendar.YEAR, -1);
|
cal.setTime(date);
|
||||||
// some padding, because no one really remembers what day of the month it is
|
boolean withinLastYear = now.get(Calendar.YEAR) == cal.get(Calendar.YEAR);
|
||||||
cal.add(GregorianCalendar.DAY_OF_MONTH, 10);
|
|
||||||
boolean withinLastYear = date.after(cal.getTime());
|
|
||||||
int format = android.text.format.DateUtils.FORMAT_ABBREV_ALL;
|
int format = android.text.format.DateUtils.FORMAT_ABBREV_ALL;
|
||||||
if (withinLastYear) {
|
if (withinLastYear) {
|
||||||
format |= android.text.format.DateUtils.FORMAT_NO_YEAR;
|
format |= android.text.format.DateUtils.FORMAT_NO_YEAR;
|
||||||
|
|
Loading…
Reference in New Issue