Commit 75cec1b3 authored by Tiago Cunha's avatar Tiago Cunha

Using the best pattern for locale when available

parent 57e4826a
package chat.rocket.android.helper; package chat.rocket.android.helper;
import android.os.Build;
import android.text.format.DateFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone; import java.util.TimeZone;
import chat.rocket.android.log.RCLog; import chat.rocket.android.log.RCLog;
...@@ -11,13 +15,34 @@ import chat.rocket.android.log.RCLog; ...@@ -11,13 +15,34 @@ import chat.rocket.android.log.RCLog;
* Utility class for converting epoch ms and date-time string. * Utility class for converting epoch ms and date-time string.
*/ */
public class DateTime { public class DateTime {
private static final String TAG = DateTime.class.getName(); private static final String TAG = "DateTime";
private static final SimpleDateFormat TIME_FORMAT;
private static final SimpleDateFormat DATE_FORMAT;
private static final SimpleDateFormat DAY_FORMAT;
private static final SimpleDateFormat DAY_TIME_FORMAT;
private static final SimpleDateFormat DATE_TIME_FORMAT;
static {
Locale locale = Locale.getDefault();
private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd"); TIME_FORMAT = new SimpleDateFormat(DateFormat.getBestDateTimePattern(locale, "HHmm"), locale);
private static final SimpleDateFormat DAY_FORMAT = new SimpleDateFormat("MM/dd"); DATE_FORMAT =
private static final SimpleDateFormat DAY_TIME_FORMAT = new SimpleDateFormat("MM/dd HH:mm"); new SimpleDateFormat(DateFormat.getBestDateTimePattern(locale, "yyyyMMdd"), locale);
private static final SimpleDateFormat DATE_TIME_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm"); DAY_FORMAT = new SimpleDateFormat(DateFormat.getBestDateTimePattern(locale, "MMdd"), locale);
DAY_TIME_FORMAT =
new SimpleDateFormat(DateFormat.getBestDateTimePattern(locale, "MMddHHmm"), locale);
DATE_TIME_FORMAT =
new SimpleDateFormat(DateFormat.getBestDateTimePattern(locale, "yyyyMMddHHmm"), locale);
} else {
TIME_FORMAT = new SimpleDateFormat("HH:mm", locale);
DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd", locale);
DAY_FORMAT = new SimpleDateFormat("MM/dd", locale);
DAY_TIME_FORMAT = new SimpleDateFormat("MM/dd HH:mm", locale);
DATE_TIME_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm", locale);
}
}
/** /**
* convert datetime ms to String. * convert datetime ms to String.
......
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