Skip to content

Commit 6323b6c

Browse files
committed
Use localized digits for Time formatting.
This fixes the digits in places like Settings' data usage page and Calendar's drop-down, for languages such as Arabic. Bug: 6811327 Change-Id: I2dafcc342e3279937735697b3748b47fdfc8e691
1 parent 315a7c0 commit 6323b6c

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

core/java/android/text/format/Time.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ public class Time {
151151
private static String sDateTimeFormat;
152152
private static String sAm;
153153
private static String sPm;
154+
private static char sZeroDigit;
154155

155156
// Referenced by native code.
156157
private static String sDateCommand = "%a %b %e %H:%M:%S %Z %Y";
@@ -325,6 +326,7 @@ public String format(String format) {
325326

326327
sAm = localeData.amPm[0];
327328
sPm = localeData.amPm[1];
329+
sZeroDigit = localeData.zeroDigit;
328330

329331
sShortMonths = localeData.shortMonthNames;
330332
sLongMonths = localeData.longMonthNames;
@@ -340,12 +342,32 @@ public String format(String format) {
340342
sLocale = locale;
341343
}
342344

343-
return format1(format);
345+
String result = format1(format);
346+
if (sZeroDigit != '0') {
347+
result = localizeDigits(result);
348+
}
349+
return result;
344350
}
345351
}
346352

347353
native private String format1(String format);
348354

355+
// TODO: unify this with java.util.Formatter's copy.
356+
private String localizeDigits(String s) {
357+
int length = s.length();
358+
int offsetToLocalizedDigits = sZeroDigit - '0';
359+
StringBuilder result = new StringBuilder(length);
360+
for (int i = 0; i < length; ++i) {
361+
char ch = s.charAt(i);
362+
if (ch >= '0' && ch <= '9') {
363+
ch += offsetToLocalizedDigits;
364+
}
365+
result.append(ch);
366+
}
367+
return result.toString();
368+
}
369+
370+
349371
/**
350372
* Return the current time in YYYYMMDDTHHMMSS<tz> format
351373
*/

0 commit comments

Comments
 (0)