@@ -249,12 +249,13 @@ public static boolean is24HourFormat(Context context) {
249249
250250 synchronized (sLocaleLock ) {
251251 sIs24HourLocale = locale ;
252- sIs24Hour = ! value .equals ("12 " );
252+ sIs24Hour = value .equals ("24 " );
253253 }
254+
255+ return sIs24Hour ;
254256 }
255257
256- boolean b24 = !(value == null || value .equals ("12" ));
257- return b24 ;
258+ return value .equals ("24" );
258259 }
259260
260261 /**
@@ -263,7 +264,7 @@ public static boolean is24HourFormat(Context context) {
263264 * @param context the application context
264265 * @return the {@link java.text.DateFormat} object that properly formats the time.
265266 */
266- public static final java .text .DateFormat getTimeFormat (Context context ) {
267+ public static java .text .DateFormat getTimeFormat (Context context ) {
267268 boolean b24 = is24HourFormat (context );
268269 int res ;
269270
@@ -283,7 +284,7 @@ public static final java.text.DateFormat getTimeFormat(Context context) {
283284 * @param context the application context
284285 * @return the {@link java.text.DateFormat} object that properly formats the date.
285286 */
286- public static final java .text .DateFormat getDateFormat (Context context ) {
287+ public static java .text .DateFormat getDateFormat (Context context ) {
287288 String value = Settings .System .getString (context .getContentResolver (),
288289 Settings .System .DATE_FORMAT );
289290
@@ -353,7 +354,7 @@ private static String getDateFormatStringForSetting(Context context, String valu
353354 * @param context the application context
354355 * @return the {@link java.text.DateFormat} object that formats the date in long form.
355356 */
356- public static final java .text .DateFormat getLongDateFormat (Context context ) {
357+ public static java .text .DateFormat getLongDateFormat (Context context ) {
357358 return java .text .DateFormat .getDateInstance (java .text .DateFormat .LONG );
358359 }
359360
@@ -363,7 +364,7 @@ public static final java.text.DateFormat getLongDateFormat(Context context) {
363364 * @param context the application context
364365 * @return the {@link java.text.DateFormat} object that formats the date in long form.
365366 */
366- public static final java .text .DateFormat getMediumDateFormat (Context context ) {
367+ public static java .text .DateFormat getMediumDateFormat (Context context ) {
367368 return java .text .DateFormat .getDateInstance (java .text .DateFormat .MEDIUM );
368369 }
369370
@@ -376,7 +377,7 @@ public static final java.text.DateFormat getMediumDateFormat(Context context) {
376377 * not just the day, month, and year, and not necessarily in the same
377378 * order returned here.
378379 */
379- public static final char [] getDateFormatOrder (Context context ) {
380+ public static char [] getDateFormatOrder (Context context ) {
380381 char [] order = new char [] {DATE , MONTH , YEAR };
381382 String value = getDateFormatString (context );
382383 int index = 0 ;
@@ -420,7 +421,7 @@ private static String getDateFormatString(Context context) {
420421 * @param inTimeInMillis in milliseconds since Jan 1, 1970 GMT
421422 * @return a {@link CharSequence} containing the requested text
422423 */
423- public static final CharSequence format (CharSequence inFormat , long inTimeInMillis ) {
424+ public static CharSequence format (CharSequence inFormat , long inTimeInMillis ) {
424425 return format (inFormat , new Date (inTimeInMillis ));
425426 }
426427
@@ -431,22 +432,84 @@ public static final CharSequence format(CharSequence inFormat, long inTimeInMill
431432 * @param inDate the date to format
432433 * @return a {@link CharSequence} containing the requested text
433434 */
434- public static final CharSequence format (CharSequence inFormat , Date inDate ) {
435+ public static CharSequence format (CharSequence inFormat , Date inDate ) {
435436 Calendar c = new GregorianCalendar ();
436437
437438 c .setTime (inDate );
438439
439440 return format (inFormat , c );
440441 }
441442
443+ /**
444+ * Indicates whether the specified format string contains seconds.
445+ *
446+ * Always returns false if the input format is null.
447+ *
448+ * @param inFormat the format string, as described in {@link android.text.format.DateFormat}
449+ *
450+ * @return true if the format string contains {@link #SECONDS}, false otherwise
451+ *
452+ * @hide
453+ */
454+ public static boolean hasSeconds (CharSequence inFormat ) {
455+ if (inFormat == null ) return false ;
456+
457+ final int length = inFormat .length ();
458+
459+ int c ;
460+ int count ;
461+
462+ for (int i = 0 ; i < length ; i += count ) {
463+ count = 1 ;
464+ c = inFormat .charAt (i );
465+
466+ if (c == QUOTE ) {
467+ count = skipQuotedText (inFormat , i , length );
468+ } else if (c == SECONDS ) {
469+ return true ;
470+ }
471+ }
472+
473+ return false ;
474+ }
475+
476+ private static int skipQuotedText (CharSequence s , int i , int len ) {
477+ if (i + 1 < len && s .charAt (i + 1 ) == QUOTE ) {
478+ return 2 ;
479+ }
480+
481+ int count = 1 ;
482+ // skip leading quote
483+ i ++;
484+
485+ while (i < len ) {
486+ char c = s .charAt (i );
487+
488+ if (c == QUOTE ) {
489+ count ++;
490+ // QUOTEQUOTE -> QUOTE
491+ if (i + 1 < len && s .charAt (i + 1 ) == QUOTE ) {
492+ i ++;
493+ } else {
494+ break ;
495+ }
496+ } else {
497+ i ++;
498+ count ++;
499+ }
500+ }
501+
502+ return count ;
503+ }
504+
442505 /**
443506 * Given a format string and a {@link java.util.Calendar} object, returns a CharSequence
444507 * containing the requested date.
445508 * @param inFormat the format string, as described in {@link android.text.format.DateFormat}
446509 * @param inDate the date to format
447510 * @return a {@link CharSequence} containing the requested text
448511 */
449- public static final CharSequence format (CharSequence inFormat , Calendar inDate ) {
512+ public static CharSequence format (CharSequence inFormat , Calendar inDate ) {
450513 SpannableStringBuilder s = new SpannableStringBuilder (inFormat );
451514 int c ;
452515 int count ;
@@ -545,7 +608,7 @@ public static final CharSequence format(CharSequence inFormat, Calendar inDate)
545608 return s .toString ();
546609 }
547610
548- private static final String getMonthString (Calendar inDate , int count , int kind ) {
611+ private static String getMonthString (Calendar inDate , int count , int kind ) {
549612 boolean standalone = (kind == STANDALONE_MONTH );
550613 int month = inDate .get (Calendar .MONTH );
551614
@@ -563,7 +626,7 @@ private static final String getMonthString(Calendar inDate, int count, int kind)
563626 }
564627 }
565628
566- private static final String getTimeZoneString (Calendar inDate , int count ) {
629+ private static String getTimeZoneString (Calendar inDate , int count ) {
567630 TimeZone tz = inDate .getTimeZone ();
568631
569632 if (count < 2 ) { // FIXME: shouldn't this be <= 2 ?
@@ -576,7 +639,7 @@ private static final String getTimeZoneString(Calendar inDate, int count) {
576639 }
577640 }
578641
579- private static final String formatZoneOffset (int offset , int count ) {
642+ private static String formatZoneOffset (int offset , int count ) {
580643 offset /= 1000 ; // milliseconds to seconds
581644 StringBuilder tb = new StringBuilder ();
582645
@@ -595,13 +658,13 @@ private static final String formatZoneOffset(int offset, int count) {
595658 return tb .toString ();
596659 }
597660
598- private static final String getYearString (Calendar inDate , int count ) {
661+ private static String getYearString (Calendar inDate , int count ) {
599662 int year = inDate .get (Calendar .YEAR );
600663 return (count <= 2 ) ? zeroPad (year % 100 , 2 )
601664 : String .format (Locale .getDefault (), "%d" , year );
602665 }
603666
604- private static final int appendQuotedText (SpannableStringBuilder s , int i , int len ) {
667+ private static int appendQuotedText (SpannableStringBuilder s , int i , int len ) {
605668 if (i + 1 < len && s .charAt (i + 1 ) == QUOTE ) {
606669 s .delete (i , i + 1 );
607670 return 1 ;
@@ -638,7 +701,7 @@ private static final int appendQuotedText(SpannableStringBuilder s, int i, int l
638701 return count ;
639702 }
640703
641- private static final String zeroPad (int inValue , int inMinDigits ) {
704+ private static String zeroPad (int inValue , int inMinDigits ) {
642705 return String .format (Locale .getDefault (), "%0" + inMinDigits + "d" , inValue );
643706 }
644707}
0 commit comments