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

Commit b5380b00 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic 'time_format_settings'

* changes:
  Extract is24HourLocale method.
  Allow null value for TIME_12_24 setting.
parents 4db08db1 20c5ef73
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3484,7 +3484,7 @@ public final class Settings {

        /** @hide */
        public static final Validator TIME_12_24_VALIDATOR =
                new DiscreteValueValidator(new String[] {"12", "24"});
                new DiscreteValueValidator(new String[] {"12", "24", null});

        /**
         * Date format string
+11 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.text.format;

import android.annotation.NonNull;
import android.content.Context;
import android.os.UserHandle;
import android.provider.Settings;
@@ -183,8 +184,17 @@ public class DateFormat {
            return value.equals("24");
        }

        final Locale locale = context.getResources().getConfiguration().locale;
        return is24HourLocale(context.getResources().getConfiguration().locale);
    }

    /**
     * Returns true if the specified locale uses a 24-hour time format by default, ignoring user
     * settings.
     * @param locale the locale to check
     * @return true if the locale uses a 24 hour time format by default, false otherwise
     * @hide
     */
    public static boolean is24HourLocale(@NonNull Locale locale) {
        synchronized (sLocaleLock) {
            if (sIs24HourLocale != null && sIs24HourLocale.equals(locale)) {
                return sIs24Hour;
+8 −0
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.Locale;

@SmallTest
@RunWith(AndroidJUnit4.class)
public class DateFormatTest {
@@ -44,4 +46,10 @@ public class DateFormatTest {

        assertFalse(DateFormat.hasDesignator("hh:mm 'yyyy'", DateFormat.YEAR));
    }

    @Test
    public void testIs24HourLocale() {
        assertFalse(DateFormat.is24HourLocale(Locale.US));
        assertTrue(DateFormat.is24HourLocale(Locale.GERMANY));
    }
}