3838public 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 /**
0 commit comments