Commit 52b38829 authored by Grigory Fedorov's avatar Grigory Fedorov

Chat message: only time (not date) is show for today's messages.

parent 0404898d
......@@ -19,7 +19,9 @@ import android.content.res.Resources;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
/**
* Helper class to get plural forms.
......@@ -127,10 +129,24 @@ public class StringUtils {
return "";
}
// today
Calendar midnight = new GregorianCalendar();
// reset hour, minutes, seconds and millis
midnight.set(Calendar.HOUR_OF_DAY, 0);
midnight.set(Calendar.MINUTE, 0);
midnight.set(Calendar.SECOND, 0);
midnight.set(Calendar.MILLISECOND, 0);
DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(context);
DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context);
return dateFormat.format(timeStamp) + " " + timeFormat.format(timeStamp);
if (timeStamp.getTime() > midnight.getTimeInMillis()) {
synchronized (TIME) {
return timeFormat.format(timeStamp);
}
} else {
DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context);
return dateFormat.format(timeStamp) + " " + timeFormat.format(timeStamp);
}
}
}
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