133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes/*
233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * Copyright (C) 2009 The Android Open Source Project
333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes *
433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * you may not use this file except in compliance with the License.
633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * You may obtain a copy of the License at
733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes *
833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes *
1033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * Unless required by applicable law or agreed to in writing, software
1133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
1233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * See the License for the specific language governing permissions and
1433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * limitations under the License.
1533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes */
1633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes
17162b0775772fa66b7eb634760a8159a60c1ddceaElliott Hughespackage libcore.icu;
1833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes
196ca85c49efc0f02d69933f60b207b964a999061fElliott Hughesimport java.text.DateFormat;
20deacd761e85ee4d75a6adbdd63225fc4a6d3088dElliott Hughesimport java.util.Arrays;
21757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughesimport java.util.HashMap;
22757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughesimport java.util.Locale;
2366e8297c70daaf001ca199e4e4ad3ba5283396d2Elliott Hughesimport libcore.util.Objects;
246ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes
2533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes/**
2633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * Passes locale-specific from ICU native code to Java.
2733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * <p>
2833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * Note that you share these; you must not alter any of the fields, nor their array elements
2933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * in the case of arrays. If you ever expose any of these things to user code, you must give
3033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes * them a clone rather than the original.
3133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes */
329672b4887f2972c1b7c5f3d1a6cf882deccf857fElliott Hughespublic final class LocaleData {
33757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    // A cache for the locale-specific data.
34757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    private static final HashMap<String, LocaleData> localeDataCache = new HashMap<String, LocaleData>();
35e2377cdd707b830d07a5708216834f7ac76ee3e1Elliott Hughes    static {
36e2377cdd707b830d07a5708216834f7ac76ee3e1Elliott Hughes        // Ensure that we pull in the locale data for the root locale, en_US, and the
37e2377cdd707b830d07a5708216834f7ac76ee3e1Elliott Hughes        // user's default locale. (All devices must support the root locale and en_US,
38e2377cdd707b830d07a5708216834f7ac76ee3e1Elliott Hughes        // and they're used for various system things like HTTP headers.) Pre-populating
39e2377cdd707b830d07a5708216834f7ac76ee3e1Elliott Hughes        // the cache is especially useful on Android because we'll share this via the Zygote.
40e2377cdd707b830d07a5708216834f7ac76ee3e1Elliott Hughes        get(Locale.ROOT);
41e2377cdd707b830d07a5708216834f7ac76ee3e1Elliott Hughes        get(Locale.US);
42e2377cdd707b830d07a5708216834f7ac76ee3e1Elliott Hughes        get(Locale.getDefault());
43e2377cdd707b830d07a5708216834f7ac76ee3e1Elliott Hughes    }
44757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
45143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes    // Used by Calendar.
4633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public Integer firstDayOfWeek;
4733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public Integer minimalDaysInFirstWeek;
48757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
49143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes    // Used by DateFormatSymbols.
50ad66a888b2e48b1a185de1b3c73fd01383a1fd04Elliott Hughes    public String[] amPm; // "AM", "PM".
51ad66a888b2e48b1a185de1b3c73fd01383a1fd04Elliott Hughes    public String[] eras; // "BC", "AD".
52757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
53ad66a888b2e48b1a185de1b3c73fd01383a1fd04Elliott Hughes    public String[] longMonthNames; // "January", ...
54ad66a888b2e48b1a185de1b3c73fd01383a1fd04Elliott Hughes    public String[] shortMonthNames; // "Jan", ...
55ad66a888b2e48b1a185de1b3c73fd01383a1fd04Elliott Hughes    public String[] tinyMonthNames; // "J", ...
56ad66a888b2e48b1a185de1b3c73fd01383a1fd04Elliott Hughes    public String[] longStandAloneMonthNames; // "January", ...
57ad66a888b2e48b1a185de1b3c73fd01383a1fd04Elliott Hughes    public String[] shortStandAloneMonthNames; // "Jan", ...
58ad66a888b2e48b1a185de1b3c73fd01383a1fd04Elliott Hughes    public String[] tinyStandAloneMonthNames; // "J", ...
59757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
60ad66a888b2e48b1a185de1b3c73fd01383a1fd04Elliott Hughes    public String[] longWeekdayNames; // "Sunday", ...
61ad66a888b2e48b1a185de1b3c73fd01383a1fd04Elliott Hughes    public String[] shortWeekdayNames; // "Sun", ...
62ad66a888b2e48b1a185de1b3c73fd01383a1fd04Elliott Hughes    public String[] tinyWeekdayNames; // "S", ...
63ad66a888b2e48b1a185de1b3c73fd01383a1fd04Elliott Hughes    public String[] longStandAloneWeekdayNames; // "Sunday", ...
64ad66a888b2e48b1a185de1b3c73fd01383a1fd04Elliott Hughes    public String[] shortStandAloneWeekdayNames; // "Sun", ...
65ad66a888b2e48b1a185de1b3c73fd01383a1fd04Elliott Hughes    public String[] tinyStandAloneWeekdayNames; // "S", ...
66757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
67c4e0797a4dd028d23e788da15c3055f83f6f37d5Elliott Hughes    // Used by frameworks/base DateSorter and DateUtils.
68c4e0797a4dd028d23e788da15c3055f83f6f37d5Elliott Hughes    public String yesterday; // "Yesterday".
69c4e0797a4dd028d23e788da15c3055f83f6f37d5Elliott Hughes    public String today; // "Today".
70c4e0797a4dd028d23e788da15c3055f83f6f37d5Elliott Hughes    public String tomorrow; // "Tomorrow".
71c4e0797a4dd028d23e788da15c3055f83f6f37d5Elliott Hughes
7233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String fullTimeFormat;
7333aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String longTimeFormat;
7433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String mediumTimeFormat;
7533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String shortTimeFormat;
76757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
7733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String fullDateFormat;
7833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String longDateFormat;
7933aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String mediumDateFormat;
8033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String shortDateFormat;
81757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
82b799123bc221b926a9f189107f2a3619a4da8874Elliott Hughes    // Used by TimePicker. Not currently used by UTS#35.
83b799123bc221b926a9f189107f2a3619a4da8874Elliott Hughes    public String narrowAm; // "a".
84b799123bc221b926a9f189107f2a3619a4da8874Elliott Hughes    public String narrowPm; // "p".
85b799123bc221b926a9f189107f2a3619a4da8874Elliott Hughes
862f5b39ddcdfc4ab7edd0a5a02801eb3dc96e0266Elliott Hughes    // shortDateFormat, but guaranteed to have 4-digit years.
872f5b39ddcdfc4ab7edd0a5a02801eb3dc96e0266Elliott Hughes    // Used by android.text.format.DateFormat.getDateFormatStringForSetting.
882f5b39ddcdfc4ab7edd0a5a02801eb3dc96e0266Elliott Hughes    public String shortDateFormat4;
892f5b39ddcdfc4ab7edd0a5a02801eb3dc96e0266Elliott Hughes
90cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes    // Used by DateFormat to implement 12- and 24-hour SHORT and MEDIUM.
91d8aa6c7b03fdb0247ae5cce6dd0e876346276a73Elliott Hughes    // The first two are also used directly by frameworks code.
92cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes    public String timeFormat_hm;
93cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes    public String timeFormat_Hm;
94cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes    public String timeFormat_hms;
95cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes    public String timeFormat_Hms;
96cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes
97143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes    // Used by DecimalFormatSymbols.
98b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes    public char zeroDigit;
99b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes    public char decimalSeparator;
100b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes    public char groupingSeparator;
101b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes    public char patternSeparator;
102a68116c0d8ff9cd517d6b765bf2b8930ed9a3e12Elliott Hughes    public String percent;
103b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes    public char perMill;
104b7e820b92c7345cdc0cd4fea50954289ae66eb67Elliott Hughes    public char monetarySeparator;
1054f3bca749bdc8be8abf7555b315f308a2c8c14a7Narayan Kamath    public String minusSign;
10690aa512eb7b126deb8d752b7474c30d3f73507b2Elliott Hughes    public String exponentSeparator;
10733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String infinity;
10833aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String NaN;
109143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes    // Also used by Currency.
11033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String currencySymbol;
11133aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String internationalCurrencySymbol;
112757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
113143e8c9cf91cfc01c3c91c8e93cad661ec7554eeElliott Hughes    // Used by DecimalFormat and NumberFormat.
11433aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String numberPattern;
11533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String integerPattern;
11633aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String currencyPattern;
11733aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    public String percentPattern;
118757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
119757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    private LocaleData() {
120757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    }
121757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
1225c0472fd7c53464e526bb833707551d85dbafec1Narayan Kamath    public static Locale mapInvalidAndNullLocales(Locale locale) {
1235c0472fd7c53464e526bb833707551d85dbafec1Narayan Kamath        if (locale == null) {
1245c0472fd7c53464e526bb833707551d85dbafec1Narayan Kamath            return Locale.getDefault();
1255c0472fd7c53464e526bb833707551d85dbafec1Narayan Kamath        }
1265c0472fd7c53464e526bb833707551d85dbafec1Narayan Kamath
1275c0472fd7c53464e526bb833707551d85dbafec1Narayan Kamath        if ("und".equals(locale.toLanguageTag())) {
1285c0472fd7c53464e526bb833707551d85dbafec1Narayan Kamath            return Locale.ROOT;
1295c0472fd7c53464e526bb833707551d85dbafec1Narayan Kamath        }
1305c0472fd7c53464e526bb833707551d85dbafec1Narayan Kamath
1315c0472fd7c53464e526bb833707551d85dbafec1Narayan Kamath        return locale;
1325c0472fd7c53464e526bb833707551d85dbafec1Narayan Kamath    }
1335c0472fd7c53464e526bb833707551d85dbafec1Narayan Kamath
134757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    /**
135757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes     * Returns a shared LocaleData for the given locale.
136757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes     */
137757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    public static LocaleData get(Locale locale) {
138148de94b69ad9ed98ebb1adf0e8eb1b1e9e33e1fNarayan Kamath        if (locale == null) {
139148de94b69ad9ed98ebb1adf0e8eb1b1e9e33e1fNarayan Kamath            throw new NullPointerException("locale == null");
140148de94b69ad9ed98ebb1adf0e8eb1b1e9e33e1fNarayan Kamath        }
141148de94b69ad9ed98ebb1adf0e8eb1b1e9e33e1fNarayan Kamath
1425c0472fd7c53464e526bb833707551d85dbafec1Narayan Kamath        final String languageTag = locale.toLanguageTag();
143757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        synchronized (localeDataCache) {
1445c0472fd7c53464e526bb833707551d85dbafec1Narayan Kamath            LocaleData localeData = localeDataCache.get(languageTag);
145757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            if (localeData != null) {
146757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes                return localeData;
147757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            }
148757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        }
1495b7b7fe6a817fdf058eefd9a716cc58a3283eb05claireho        LocaleData newLocaleData = initLocaleData(locale);
150757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        synchronized (localeDataCache) {
1515c0472fd7c53464e526bb833707551d85dbafec1Narayan Kamath            LocaleData localeData = localeDataCache.get(languageTag);
152757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            if (localeData != null) {
153757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes                return localeData;
154757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            }
1555c0472fd7c53464e526bb833707551d85dbafec1Narayan Kamath            localeDataCache.put(languageTag, newLocaleData);
156757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            return newLocaleData;
157757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        }
158757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    }
159757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
16033aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    @Override public String toString() {
16166e8297c70daaf001ca199e4e4ad3ba5283396d2Elliott Hughes        return Objects.toString(this);
16233aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes    }
163757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
1646ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes    public String getDateFormat(int style) {
1656ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        switch (style) {
1666ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.SHORT:
1676ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return shortDateFormat;
1686ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.MEDIUM:
1696ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return mediumDateFormat;
1706ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.LONG:
1716ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return longDateFormat;
1726ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.FULL:
1736ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return fullDateFormat;
1746ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        }
1756ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        throw new AssertionError();
1766ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes    }
177757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
1786ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes    public String getTimeFormat(int style) {
1796ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        switch (style) {
1806ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.SHORT:
181cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes            if (DateFormat.is24Hour == null) {
182cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes                return shortTimeFormat;
183cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes            } else {
184cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes                return DateFormat.is24Hour ? timeFormat_Hm : timeFormat_hm;
185cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes            }
1866ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.MEDIUM:
187cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes            if (DateFormat.is24Hour == null) {
188cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes                return mediumTimeFormat;
189cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes            } else {
190cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes                return DateFormat.is24Hour ? timeFormat_Hms : timeFormat_hms;
191cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes            }
1926ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.LONG:
193cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes            // CLDR doesn't really have anything we can use to obey the 12-/24-hour preference.
1946ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return longTimeFormat;
1956ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        case DateFormat.FULL:
196cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes            // CLDR doesn't really have anything we can use to obey the 12-/24-hour preference.
1976ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes            return fullTimeFormat;
1986ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        }
1996ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes        throw new AssertionError();
2006ca85c49efc0f02d69933f60b207b964a999061fElliott Hughes    }
201757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes
202757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    private static LocaleData initLocaleData(Locale locale) {
203757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        LocaleData localeData = new LocaleData();
2045c0472fd7c53464e526bb833707551d85dbafec1Narayan Kamath        if (!ICU.initLocaleDataNative(locale.toLanguageTag(), localeData)) {
205757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            throw new AssertionError("couldn't initialize LocaleData for locale " + locale);
206757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        }
207783112d47e2236b6a7e2315c2e50166d755422a7Elliott Hughes
208cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes        // Get the SHORT and MEDIUM 12- and 24-hour time format strings.
209cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes        localeData.timeFormat_hm = ICU.getBestDateTimePattern("hm", locale);
210cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes        localeData.timeFormat_Hm = ICU.getBestDateTimePattern("Hm", locale);
211cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes        localeData.timeFormat_hms = ICU.getBestDateTimePattern("hms", locale);
212cafe1a748caf89091d2f1c3956a43daf23b9403bElliott Hughes        localeData.timeFormat_Hms = ICU.getBestDateTimePattern("Hms", locale);
213783112d47e2236b6a7e2315c2e50166d755422a7Elliott Hughes
214783112d47e2236b6a7e2315c2e50166d755422a7Elliott Hughes        // Fix up a couple of patterns.
215757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        if (localeData.fullTimeFormat != null) {
216757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // There are some full time format patterns in ICU that use the pattern character 'v'.
217757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // Java doesn't accept this, so we replace it with 'z' which has about the same result
218757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // as 'v', the timezone name.
219757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // 'v' -> "PT", 'z' -> "PST", v is the generic timezone and z the standard tz
220757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // "vvvv" -> "Pacific Time", "zzzz" -> "Pacific Standard Time"
221757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            localeData.fullTimeFormat = localeData.fullTimeFormat.replace('v', 'z');
222757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        }
223757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        if (localeData.numberPattern != null) {
224757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // The number pattern might contain positive and negative subpatterns. Arabic, for
225757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // example, might look like "#,##0.###;#,##0.###-" because the minus sign should be
226757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // written last. Macedonian supposedly looks something like "#,##0.###;(#,##0.###)".
227757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // (The negative subpattern is optional, though, and not present in most locales.)
228757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // By only swallowing '#'es and ','s after the '.', we ensure that we don't
229757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            // accidentally eat too much.
230757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes            localeData.integerPattern = localeData.numberPattern.replaceAll("\\.[#,]*", "");
231757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        }
2322f5b39ddcdfc4ab7edd0a5a02801eb3dc96e0266Elliott Hughes        localeData.shortDateFormat4 = localeData.shortDateFormat.replaceAll("\\byy\\b", "y");
233757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes        return localeData;
234757a7942eed2b0aa457f8517a0259d2ac82c5b18Elliott Hughes    }
23533aa6eb602478e7f51ac16f30c88db3566022886Elliott Hughes}
236