Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6323b6c6 authored by Elliott Hughes's avatar Elliott Hughes
Browse files

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
parent 315a7c03
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -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
     */