Commit bca36b8c authored by Grigory Fedorov's avatar Grigory Fedorov

StringUtils: time format changed (for chats).

parent 1a820d39
...@@ -14,10 +14,13 @@ ...@@ -14,10 +14,13 @@
*/ */
package com.xabber.android.utils; package com.xabber.android.utils;
import android.content.res.Resources;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar;
import android.content.res.Resources;
/** /**
* Helper class to get plural forms. * Helper class to get plural forms.
...@@ -32,7 +35,7 @@ public class StringUtils { ...@@ -32,7 +35,7 @@ public class StringUtils {
static { static {
DATE_TIME = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DATE_TIME = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
DateFormat.SHORT); DateFormat.SHORT);
TIME = DateFormat.getTimeInstance(DateFormat.MEDIUM); TIME = new SimpleDateFormat("H:mm");
} }
private StringUtils() { private StringUtils() {
...@@ -121,11 +124,19 @@ public class StringUtils { ...@@ -121,11 +124,19 @@ public class StringUtils {
* @return String with time or with date and time depend on current time. * @return String with time or with date and time depend on current time.
*/ */
public static String getSmartTimeText(Date timeStamp) { public static String getSmartTimeText(Date timeStamp) {
if (timeStamp == null) if (timeStamp == null) {
return ""; return "";
Date date = new Date(); }
long delta = date.getTime() - timeStamp.getTime();
if (delta < 20 * 60 * 60 * 1000) // 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);
if (timeStamp.getTime() > midnight.getTimeInMillis())
synchronized (TIME) { synchronized (TIME) {
return TIME.format(timeStamp); return TIME.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