Commit c305afcf authored by Leonardo Aramaki's avatar Leonardo Aramaki

Set date label to Todat or Yesterday when applied for best readability

parent 82847d85
......@@ -5,7 +5,10 @@ import android.text.format.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
......@@ -56,7 +59,7 @@ public class DateTime {
case DAY:
return DAY_FORMAT.format(cal.getTime());
case DATE:
return DATE_FORMAT.format(cal.getTime());
return getDateFormat(cal.getTime());
case TIME:
return TIME_FORMAT.format(cal.getTime());
case DATE_TIME:
......@@ -81,6 +84,22 @@ public class DateTime {
}
}
private static String getDateFormat(Date dateTime) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(dateTime);
Calendar today = Calendar.getInstance();
Calendar yesterday = Calendar.getInstance();
yesterday.add(Calendar.DATE, -1);
if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) {
return "Today";
} else if (calendar.get(Calendar.YEAR) == yesterday.get(Calendar.YEAR) && calendar.get(Calendar.DAY_OF_YEAR) == yesterday.get(Calendar.DAY_OF_YEAR)) {
return "Yesterday";
} else {
return DATE_FORMAT.format(dateTime);
}
}
/**
* parse datetime string to ms.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment