diff options
| author | 2013-03-11 14:49:44 -0700 | |
|---|---|---|
| committer | 2013-03-11 14:49:44 -0700 | |
| commit | 7a89f62877a03d249d9e7d0562058b973d747c49 (patch) | |
| tree | 4371aa4f085a654617ebf7aca51a11eda644fb41 | |
| parent | 21d3f294831f7a15c5e746b3dae3e6ec0de883a8 (diff) | |
Fix DateFormat k and h, and implement K and H for the first time.
Bug: 8359981
Change-Id: I52ef937a77e9e28f2719c2ee6f59e4b74514f0b2
| -rw-r--r-- | core/java/android/text/format/DateFormat.java | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/core/java/android/text/format/DateFormat.java b/core/java/android/text/format/DateFormat.java index 167a834ad3d8..ef2c24871793 100644 --- a/core/java/android/text/format/DateFormat.java +++ b/core/java/android/text/format/DateFormat.java @@ -46,7 +46,7 @@ import libcore.icu.LocaleData; * <p>The format methods in this class implement a subset of Unicode * <a href="http://www.unicode.org/reports/tr35/#Date_Format_Patterns">UTS #35</a> patterns. * The subset supported by this class includes the following format characters: - * {@code acdEhkLMmsyz}. See {@link java.text.SimpleDateFormat} for more documentation + * {@code acdEHhLKkLMmsyz}. See {@link java.text.SimpleDateFormat} for more documentation * about patterns, or if you need a more compete implementation. */ public class DateFormat { @@ -191,7 +191,6 @@ public class DateFormat { public static java.text.DateFormat getDateFormatForSetting(Context context, String value) { String format = getDateFormatStringForSetting(context, value); - return new java.text.SimpleDateFormat(format); } @@ -431,12 +430,25 @@ public class DateFormat { replacement = getDayOfWeekString(localeData, inDate.get(Calendar.DAY_OF_WEEK), count, c); break; - case 'h': - int hour = inDate.get(Calendar.HOUR); - replacement = zeroPad(hour == 0 ? 24 : hour, count); + case 'K': // hour in am/pm (0-11) + case 'h': // hour in am/pm (1-12) + { + int hour = inDate.get(Calendar.HOUR); + if (c == 'h' && hour == 0) { + hour = 12; + } + replacement = zeroPad(hour, count); + } break; - case 'k': - replacement = zeroPad(inDate.get(Calendar.HOUR_OF_DAY), count); + case 'H': // hour in day (0-23) + case 'k': // hour in day (1-24) + { + int hour = inDate.get(Calendar.HOUR_OF_DAY); + if (c == 'k' && hour == 0) { + hour = 24; + } + replacement = zeroPad(hour, count); + } break; case 'L': case 'M': |