Skip to content

Commit 08153ee

Browse files
committed
Switch DateUtils and Time over to using the CLDR for all week and month names.
(cherry-pick of 99c406e.) Conflicts: core/res/res/values-fa/donottranslate-cldr.xml core/res/res/values/public.xml Bug: 6811501 Change-Id: I2ad9608ae34804e02c6b0271197e96611df12b0a
1 parent 23321b8 commit 08153ee

File tree

76 files changed

+47
-6272
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+47
-6272
lines changed

core/java/android/text/format/DateUtils.java

Lines changed: 29 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -38,98 +38,6 @@
3838
public class DateUtils
3939
{
4040
private static final Object sLock = new Object();
41-
private static final int[] sDaysLong = new int[] {
42-
com.android.internal.R.string.day_of_week_long_sunday,
43-
com.android.internal.R.string.day_of_week_long_monday,
44-
com.android.internal.R.string.day_of_week_long_tuesday,
45-
com.android.internal.R.string.day_of_week_long_wednesday,
46-
com.android.internal.R.string.day_of_week_long_thursday,
47-
com.android.internal.R.string.day_of_week_long_friday,
48-
com.android.internal.R.string.day_of_week_long_saturday,
49-
};
50-
private static final int[] sDaysMedium = new int[] {
51-
com.android.internal.R.string.day_of_week_medium_sunday,
52-
com.android.internal.R.string.day_of_week_medium_monday,
53-
com.android.internal.R.string.day_of_week_medium_tuesday,
54-
com.android.internal.R.string.day_of_week_medium_wednesday,
55-
com.android.internal.R.string.day_of_week_medium_thursday,
56-
com.android.internal.R.string.day_of_week_medium_friday,
57-
com.android.internal.R.string.day_of_week_medium_saturday,
58-
};
59-
private static final int[] sDaysShort = new int[] {
60-
com.android.internal.R.string.day_of_week_short_sunday,
61-
com.android.internal.R.string.day_of_week_short_monday,
62-
com.android.internal.R.string.day_of_week_short_tuesday,
63-
com.android.internal.R.string.day_of_week_short_wednesday,
64-
com.android.internal.R.string.day_of_week_short_thursday,
65-
com.android.internal.R.string.day_of_week_short_friday,
66-
com.android.internal.R.string.day_of_week_short_saturday,
67-
};
68-
private static final int[] sDaysShortest = new int[] {
69-
com.android.internal.R.string.day_of_week_shortest_sunday,
70-
com.android.internal.R.string.day_of_week_shortest_monday,
71-
com.android.internal.R.string.day_of_week_shortest_tuesday,
72-
com.android.internal.R.string.day_of_week_shortest_wednesday,
73-
com.android.internal.R.string.day_of_week_shortest_thursday,
74-
com.android.internal.R.string.day_of_week_shortest_friday,
75-
com.android.internal.R.string.day_of_week_shortest_saturday,
76-
};
77-
private static final int[] sMonthsStandaloneLong = new int [] {
78-
com.android.internal.R.string.month_long_standalone_january,
79-
com.android.internal.R.string.month_long_standalone_february,
80-
com.android.internal.R.string.month_long_standalone_march,
81-
com.android.internal.R.string.month_long_standalone_april,
82-
com.android.internal.R.string.month_long_standalone_may,
83-
com.android.internal.R.string.month_long_standalone_june,
84-
com.android.internal.R.string.month_long_standalone_july,
85-
com.android.internal.R.string.month_long_standalone_august,
86-
com.android.internal.R.string.month_long_standalone_september,
87-
com.android.internal.R.string.month_long_standalone_october,
88-
com.android.internal.R.string.month_long_standalone_november,
89-
com.android.internal.R.string.month_long_standalone_december,
90-
};
91-
private static final int[] sMonthsLong = new int [] {
92-
com.android.internal.R.string.month_long_january,
93-
com.android.internal.R.string.month_long_february,
94-
com.android.internal.R.string.month_long_march,
95-
com.android.internal.R.string.month_long_april,
96-
com.android.internal.R.string.month_long_may,
97-
com.android.internal.R.string.month_long_june,
98-
com.android.internal.R.string.month_long_july,
99-
com.android.internal.R.string.month_long_august,
100-
com.android.internal.R.string.month_long_september,
101-
com.android.internal.R.string.month_long_october,
102-
com.android.internal.R.string.month_long_november,
103-
com.android.internal.R.string.month_long_december,
104-
};
105-
private static final int[] sMonthsMedium = new int [] {
106-
com.android.internal.R.string.month_medium_january,
107-
com.android.internal.R.string.month_medium_february,
108-
com.android.internal.R.string.month_medium_march,
109-
com.android.internal.R.string.month_medium_april,
110-
com.android.internal.R.string.month_medium_may,
111-
com.android.internal.R.string.month_medium_june,
112-
com.android.internal.R.string.month_medium_july,
113-
com.android.internal.R.string.month_medium_august,
114-
com.android.internal.R.string.month_medium_september,
115-
com.android.internal.R.string.month_medium_october,
116-
com.android.internal.R.string.month_medium_november,
117-
com.android.internal.R.string.month_medium_december,
118-
};
119-
private static final int[] sMonthsShortest = new int [] {
120-
com.android.internal.R.string.month_shortest_january,
121-
com.android.internal.R.string.month_shortest_february,
122-
com.android.internal.R.string.month_shortest_march,
123-
com.android.internal.R.string.month_shortest_april,
124-
com.android.internal.R.string.month_shortest_may,
125-
com.android.internal.R.string.month_shortest_june,
126-
com.android.internal.R.string.month_shortest_july,
127-
com.android.internal.R.string.month_shortest_august,
128-
com.android.internal.R.string.month_shortest_september,
129-
com.android.internal.R.string.month_shortest_october,
130-
com.android.internal.R.string.month_shortest_november,
131-
com.android.internal.R.string.month_shortest_december,
132-
};
13341
private static Configuration sLastConfig;
13442
private static java.text.DateFormat sStatusTimeFormat;
13543
private static String sElapsedFormatMMSS;
@@ -334,18 +242,17 @@ public class DateUtils
334242
*/
335243
@Deprecated
336244
public static String getDayOfWeekString(int dayOfWeek, int abbrev) {
337-
int[] list;
245+
LocaleData d = LocaleData.get(Locale.getDefault());
246+
String[] names;
338247
switch (abbrev) {
339-
case LENGTH_LONG: list = sDaysLong; break;
340-
case LENGTH_MEDIUM: list = sDaysMedium; break;
341-
case LENGTH_SHORT: list = sDaysShort; break;
342-
case LENGTH_SHORTER: list = sDaysShort; break;
343-
case LENGTH_SHORTEST: list = sDaysShortest; break;
344-
default: list = sDaysMedium; break;
248+
case LENGTH_LONG: names = d.longWeekdayNames; break;
249+
case LENGTH_MEDIUM: names = d.shortWeekdayNames; break;
250+
case LENGTH_SHORT: names = d.shortWeekdayNames; break; // TODO
251+
case LENGTH_SHORTER: names = d.shortWeekdayNames; break; // TODO
252+
case LENGTH_SHORTEST: names = d.tinyWeekdayNames; break;
253+
default: names = d.shortWeekdayNames; break;
345254
}
346-
347-
Resources r = Resources.getSystem();
348-
return r.getString(list[dayOfWeek - Calendar.SUNDAY]);
255+
return names[dayOfWeek];
349256
}
350257

351258
/**
@@ -373,22 +280,21 @@ public static String getAMPMString(int ampm) {
373280
*/
374281
@Deprecated
375282
public static String getMonthString(int month, int abbrev) {
376-
// Note that here we use sMonthsMedium for MEDIUM, SHORT and SHORTER.
283+
// Note that here we use d.shortMonthNames for MEDIUM, SHORT and SHORTER.
377284
// This is a shortcut to not spam the translators with too many variations
378285
// of the same string. If we find that in a language the distinction
379286
// is necessary, we can can add more without changing this API.
380-
int[] list;
287+
LocaleData d = LocaleData.get(Locale.getDefault());
288+
String[] names;
381289
switch (abbrev) {
382-
case LENGTH_LONG: list = sMonthsLong; break;
383-
case LENGTH_MEDIUM: list = sMonthsMedium; break;
384-
case LENGTH_SHORT: list = sMonthsMedium; break;
385-
case LENGTH_SHORTER: list = sMonthsMedium; break;
386-
case LENGTH_SHORTEST: list = sMonthsShortest; break;
387-
default: list = sMonthsMedium; break;
290+
case LENGTH_LONG: names = d.longMonthNames; break;
291+
case LENGTH_MEDIUM: names = d.shortMonthNames; break;
292+
case LENGTH_SHORT: names = d.shortMonthNames; break;
293+
case LENGTH_SHORTER: names = d.shortMonthNames; break;
294+
case LENGTH_SHORTEST: names = d.tinyMonthNames; break;
295+
default: names = d.shortMonthNames; break;
388296
}
389-
390-
Resources r = Resources.getSystem();
391-
return r.getString(list[month - Calendar.JANUARY]);
297+
return names[month];
392298
}
393299

394300
/**
@@ -408,23 +314,22 @@ public static String getMonthString(int month, int abbrev) {
408314
*/
409315
@Deprecated
410316
public static String getStandaloneMonthString(int month, int abbrev) {
411-
// Note that here we use sMonthsMedium for MEDIUM, SHORT and SHORTER.
317+
// Note that here we use d.shortMonthNames for MEDIUM, SHORT and SHORTER.
412318
// This is a shortcut to not spam the translators with too many variations
413319
// of the same string. If we find that in a language the distinction
414320
// is necessary, we can can add more without changing this API.
415-
int[] list;
321+
LocaleData d = LocaleData.get(Locale.getDefault());
322+
String[] names;
416323
switch (abbrev) {
417-
case LENGTH_LONG: list = sMonthsStandaloneLong;
324+
case LENGTH_LONG: names = d.longStandAloneMonthNames;
418325
break;
419-
case LENGTH_MEDIUM: list = sMonthsMedium; break;
420-
case LENGTH_SHORT: list = sMonthsMedium; break;
421-
case LENGTH_SHORTER: list = sMonthsMedium; break;
422-
case LENGTH_SHORTEST: list = sMonthsShortest; break;
423-
default: list = sMonthsMedium; break;
326+
case LENGTH_MEDIUM: names = d.shortMonthNames; break;
327+
case LENGTH_SHORT: names = d.shortMonthNames; break;
328+
case LENGTH_SHORTER: names = d.shortMonthNames; break;
329+
case LENGTH_SHORTEST: names = d.tinyMonthNames; break;
330+
default: names = d.shortMonthNames; break;
424331
}
425-
426-
Resources r = Resources.getSystem();
427-
return r.getString(list[month - Calendar.JANUARY]);
332+
return names[month];
428333
}
429334

430335
/**

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

Lines changed: 11 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -319,76 +319,22 @@ public String format(String format) {
319319
Locale locale = Locale.getDefault();
320320

321321
if (sLocale == null || locale == null || !(locale.equals(sLocale))) {
322-
Resources r = Resources.getSystem();
322+
LocaleData localeData = LocaleData.get(locale);
323+
324+
sAm = localeData.amPm[0];
325+
sPm = localeData.amPm[1];
326+
327+
sShortMonths = localeData.shortMonthNames;
328+
sLongMonths = localeData.longMonthNames;
329+
sLongStandaloneMonths = localeData.longStandAloneMonthNames;
330+
sShortWeekdays = localeData.shortWeekdayNames;
331+
sLongWeekdays = localeData.longWeekdayNames;
323332

324-
sShortMonths = new String[] {
325-
r.getString(com.android.internal.R.string.month_medium_january),
326-
r.getString(com.android.internal.R.string.month_medium_february),
327-
r.getString(com.android.internal.R.string.month_medium_march),
328-
r.getString(com.android.internal.R.string.month_medium_april),
329-
r.getString(com.android.internal.R.string.month_medium_may),
330-
r.getString(com.android.internal.R.string.month_medium_june),
331-
r.getString(com.android.internal.R.string.month_medium_july),
332-
r.getString(com.android.internal.R.string.month_medium_august),
333-
r.getString(com.android.internal.R.string.month_medium_september),
334-
r.getString(com.android.internal.R.string.month_medium_october),
335-
r.getString(com.android.internal.R.string.month_medium_november),
336-
r.getString(com.android.internal.R.string.month_medium_december),
337-
};
338-
sLongMonths = new String[] {
339-
r.getString(com.android.internal.R.string.month_long_january),
340-
r.getString(com.android.internal.R.string.month_long_february),
341-
r.getString(com.android.internal.R.string.month_long_march),
342-
r.getString(com.android.internal.R.string.month_long_april),
343-
r.getString(com.android.internal.R.string.month_long_may),
344-
r.getString(com.android.internal.R.string.month_long_june),
345-
r.getString(com.android.internal.R.string.month_long_july),
346-
r.getString(com.android.internal.R.string.month_long_august),
347-
r.getString(com.android.internal.R.string.month_long_september),
348-
r.getString(com.android.internal.R.string.month_long_october),
349-
r.getString(com.android.internal.R.string.month_long_november),
350-
r.getString(com.android.internal.R.string.month_long_december),
351-
};
352-
sLongStandaloneMonths = new String[] {
353-
r.getString(com.android.internal.R.string.month_long_standalone_january),
354-
r.getString(com.android.internal.R.string.month_long_standalone_february),
355-
r.getString(com.android.internal.R.string.month_long_standalone_march),
356-
r.getString(com.android.internal.R.string.month_long_standalone_april),
357-
r.getString(com.android.internal.R.string.month_long_standalone_may),
358-
r.getString(com.android.internal.R.string.month_long_standalone_june),
359-
r.getString(com.android.internal.R.string.month_long_standalone_july),
360-
r.getString(com.android.internal.R.string.month_long_standalone_august),
361-
r.getString(com.android.internal.R.string.month_long_standalone_september),
362-
r.getString(com.android.internal.R.string.month_long_standalone_october),
363-
r.getString(com.android.internal.R.string.month_long_standalone_november),
364-
r.getString(com.android.internal.R.string.month_long_standalone_december),
365-
};
366-
sShortWeekdays = new String[] {
367-
r.getString(com.android.internal.R.string.day_of_week_medium_sunday),
368-
r.getString(com.android.internal.R.string.day_of_week_medium_monday),
369-
r.getString(com.android.internal.R.string.day_of_week_medium_tuesday),
370-
r.getString(com.android.internal.R.string.day_of_week_medium_wednesday),
371-
r.getString(com.android.internal.R.string.day_of_week_medium_thursday),
372-
r.getString(com.android.internal.R.string.day_of_week_medium_friday),
373-
r.getString(com.android.internal.R.string.day_of_week_medium_saturday),
374-
};
375-
sLongWeekdays = new String[] {
376-
r.getString(com.android.internal.R.string.day_of_week_long_sunday),
377-
r.getString(com.android.internal.R.string.day_of_week_long_monday),
378-
r.getString(com.android.internal.R.string.day_of_week_long_tuesday),
379-
r.getString(com.android.internal.R.string.day_of_week_long_wednesday),
380-
r.getString(com.android.internal.R.string.day_of_week_long_thursday),
381-
r.getString(com.android.internal.R.string.day_of_week_long_friday),
382-
r.getString(com.android.internal.R.string.day_of_week_long_saturday),
383-
};
333+
Resources r = Resources.getSystem();
384334
sTimeOnlyFormat = r.getString(com.android.internal.R.string.time_of_day);
385335
sDateOnlyFormat = r.getString(com.android.internal.R.string.month_day_year);
386336
sDateTimeFormat = r.getString(com.android.internal.R.string.date_and_time);
387337

388-
LocaleData localeData = LocaleData.get(locale);
389-
sAm = localeData.amPm[0];
390-
sPm = localeData.amPm[1];
391-
392338
sLocale = locale;
393339
}
394340

core/jni/android_text_format_Time.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,31 +239,36 @@ static jstring android_text_format_Time_format(JNIEnv* env, jobject This,
239239
jobjectArray ja;
240240
ja = (jobjectArray) env->GetStaticObjectField(timeClass, g_shortMonthsField);
241241
for (int i = 0; i < 12; i++) {
242+
// Calendar.JANUARY == 0.
242243
js_mon[i] = (jstring) env->NewGlobalRef(env->GetObjectArrayElement(ja, i));
243244
locale.mon[i] = env->GetStringUTFChars(js_mon[i], NULL);
244245
}
245246

246247
ja = (jobjectArray) env->GetStaticObjectField(timeClass, g_longMonthsField);
247248
for (int i = 0; i < 12; i++) {
249+
// Calendar.JANUARY == 0.
248250
js_month[i] = (jstring) env->NewGlobalRef(env->GetObjectArrayElement(ja, i));
249251
locale.month[i] = env->GetStringUTFChars(js_month[i], NULL);
250252
}
251253

252254
ja = (jobjectArray) env->GetStaticObjectField(timeClass, g_longStandaloneMonthsField);
253255
for (int i = 0; i < 12; i++) {
256+
// Calendar.JANUARY == 0.
254257
js_standalone_month[i] = (jstring) env->NewGlobalRef(env->GetObjectArrayElement(ja, i));
255258
locale.standalone_month[i] = env->GetStringUTFChars(js_standalone_month[i], NULL);
256259
}
257260

258261
ja = (jobjectArray) env->GetStaticObjectField(timeClass, g_shortWeekdaysField);
259262
for (int i = 0; i < 7; i++) {
260-
js_wday[i] = (jstring) env->NewGlobalRef(env->GetObjectArrayElement(ja, i));
263+
// Calendar.SUNDAY == 1, and there's an empty string in element 0.
264+
js_wday[i] = (jstring) env->NewGlobalRef(env->GetObjectArrayElement(ja, i + 1));
261265
locale.wday[i] = env->GetStringUTFChars(js_wday[i], NULL);
262266
}
263267

264268
ja = (jobjectArray) env->GetStaticObjectField(timeClass, g_longWeekdaysField);
265269
for (int i = 0; i < 7; i++) {
266-
js_weekday[i] = (jstring) env->NewGlobalRef(env->GetObjectArrayElement(ja, i));
270+
// Calendar.SUNDAY == 1, and there's an empty string in element 0.
271+
js_weekday[i] = (jstring) env->NewGlobalRef(env->GetObjectArrayElement(ja, i + 1));
267272
locale.weekday[i] = env->GetStringUTFChars(js_weekday[i], NULL);
268273
}
269274

0 commit comments

Comments
 (0)