summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/text/format/Time.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/core/java/android/text/format/Time.java b/core/java/android/text/format/Time.java
index e2de8f2..5ef86b1 100644
--- a/core/java/android/text/format/Time.java
+++ b/core/java/android/text/format/Time.java
@@ -151,6 +151,7 @@ public class Time {
private static String sDateTimeFormat;
private static String sAm;
private static String sPm;
+ private static char sZeroDigit;
// Referenced by native code.
private static String sDateCommand = "%a %b %e %H:%M:%S %Z %Y";
@@ -325,6 +326,7 @@ public class Time {
sAm = localeData.amPm[0];
sPm = localeData.amPm[1];
+ sZeroDigit = localeData.zeroDigit;
sShortMonths = localeData.shortMonthNames;
sLongMonths = localeData.longMonthNames;
@@ -340,12 +342,32 @@ public class Time {
sLocale = locale;
}
- return format1(format);
+ String result = format1(format);
+ if (sZeroDigit != '0') {
+ result = localizeDigits(result);
+ }
+ return result;
}
}
native private String format1(String format);
+ // TODO: unify this with java.util.Formatter's copy.
+ private String localizeDigits(String s) {
+ int length = s.length();
+ int offsetToLocalizedDigits = sZeroDigit - '0';
+ StringBuilder result = new StringBuilder(length);
+ for (int i = 0; i < length; ++i) {
+ char ch = s.charAt(i);
+ if (ch >= '0' && ch <= '9') {
+ ch += offsetToLocalizedDigits;
+ }
+ result.append(ch);
+ }
+ return result.toString();
+ }
+
+
/**
* Return the current time in YYYYMMDDTHHMMSS<tz> format
*/