Improve date localization for API >= 18 (4.3, JELLY_BEAN_MR2)

Fixes #3102
Closes #4597
pull/1/head
Geonu Kang 9 years ago committed by Moxie Marlinspike
parent e4e8511b4c
commit c4f9bc2b5e

@ -34,7 +34,8 @@
<TableLayout android:id="@+id/metadata_container" <TableLayout android:id="@+id/metadata_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:shrinkColumns="1">
<TableRow android:id="@+id/sent_container" <TableRow android:id="@+id/sent_container"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -51,7 +52,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/message_details_table_row_pad" android:layout_marginLeft="@dimen/message_details_table_row_pad"
tools:text="Jan 18, 9:29AM" /> tools:text="Jan 18, 2015, 12:29:37 AM GMT-08:00" />
</TableRow> </TableRow>
@ -70,7 +71,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/message_details_table_row_pad" android:layout_marginLeft="@dimen/message_details_table_row_pad"
tools:text="Jan 18, 9:31AM" /> tools:text="Jan 18, 2015, 12:31:15 AM GMT-08:00" />
</TableRow> </TableRow>

@ -17,6 +17,7 @@
package org.thoughtcrime.securesms.util; package org.thoughtcrime.securesms.util;
import android.content.Context; import android.content.Context;
import android.os.Build;
import android.text.format.DateFormat; import android.text.format.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -41,7 +42,7 @@ public class DateUtils extends android.text.format.DateUtils {
} }
private static String getFormattedDateTime(long time, String template, Locale locale) { private static String getFormattedDateTime(long time, String template, Locale locale) {
String localizedPattern = new SimpleDateFormat(template, locale).toLocalizedPattern(); final String localizedPattern = getLocalizedPattern(template, locale);
return new SimpleDateFormat(localizedPattern, locale).format(new Date(time)); return new SimpleDateFormat(localizedPattern, locale).format(new Date(time));
} }
@ -86,12 +87,19 @@ public class DateUtils extends android.text.format.DateUtils {
String dateFormatPattern; String dateFormatPattern;
if (DateFormat.is24HourFormat(context)) { if (DateFormat.is24HourFormat(context)) {
dateFormatPattern = "MMM d, yyyy HH:mm:ss zzz"; dateFormatPattern = getLocalizedPattern("MMM d, yyyy HH:mm:ss zzz", locale);
} else { } else {
dateFormatPattern = "MMM d, yyyy hh:mm:ss a zzz"; dateFormatPattern = getLocalizedPattern("MMM d, yyyy hh:mm:ss a zzz", locale);
} }
return new SimpleDateFormat(dateFormatPattern, locale); return new SimpleDateFormat(dateFormatPattern, locale);
} }
private static String getLocalizedPattern(String template, Locale locale) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
return DateFormat.getBestDateTimePattern(locale, template);
} else {
return new SimpleDateFormat(template, locale).toLocalizedPattern();
}
}
} }

Loading…
Cancel
Save