Java Code Examples for java.text.DateFormat#getAvailableLocales()

The following examples show how to use java.text.DateFormat#getAvailableLocales() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtendedMessageFormatTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test the built in date/time formats
 */
public void testBuiltInDateTimeFormat() {
    Calendar cal = Calendar.getInstance();
    cal.set(2007, Calendar.JANUARY, 23, 18, 33, 05);
    Object[] args = new Object[] {cal.getTime()};
    Locale[] availableLocales = DateFormat.getAvailableLocales();

    checkBuiltInFormat("1: {0,date,short}",    args, availableLocales);
    checkBuiltInFormat("2: {0,date,medium}",   args, availableLocales);
    checkBuiltInFormat("3: {0,date,long}",     args, availableLocales);
    checkBuiltInFormat("4: {0,date,full}",     args, availableLocales);
    checkBuiltInFormat("5: {0,date,d MMM yy}", args, availableLocales);
    checkBuiltInFormat("6: {0,time,short}",    args, availableLocales);
    checkBuiltInFormat("7: {0,time,medium}",   args, availableLocales);
    checkBuiltInFormat("8: {0,time,long}",     args, availableLocales);
    checkBuiltInFormat("9: {0,time,full}",     args, availableLocales);
    checkBuiltInFormat("10: {0,time,HH:mm}",   args, availableLocales);
    checkBuiltInFormat("11: {0,date}",         args, availableLocales);
    checkBuiltInFormat("12: {0,time}",         args, availableLocales);
}
 
Example 2
Source File: CalendarRegression.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void Test4106136() {
    Locale saveLocale = Locale.getDefault();
    try {
        Locale[] locales = {Locale.CHINESE, Locale.CHINA};
        for (int i = 0; i < locales.length; ++i) {
            Locale.setDefault(locales[i]);
            int[] n = {
                getAvailableLocales().length,
                DateFormat.getAvailableLocales().length,
                NumberFormat.getAvailableLocales().length};
            for (int j = 0; j < n.length; ++j) {
                if (n[j] == 0) {
                    errln("Fail: No locales for " + locales[i]);
                }
            }
        }
    } finally {
        Locale.setDefault(saveLocale);
    }
}
 
Example 3
Source File: ExtendedMessageFormatTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test the built in date/time formats
 */
@Test
public void testBuiltInDateTimeFormat() {
    final Calendar cal = Calendar.getInstance();
    cal.set(2007, Calendar.JANUARY, 23, 18, 33, 05);
    final Object[] args = new Object[] {cal.getTime()};
    final Locale[] availableLocales = DateFormat.getAvailableLocales();

    checkBuiltInFormat("1: {0,date,short}",    args, availableLocales);
    checkBuiltInFormat("2: {0,date,medium}",   args, availableLocales);
    checkBuiltInFormat("3: {0,date,long}",     args, availableLocales);
    checkBuiltInFormat("4: {0,date,full}",     args, availableLocales);
    checkBuiltInFormat("5: {0,date,d MMM yy}", args, availableLocales);
    checkBuiltInFormat("6: {0,time,short}",    args, availableLocales);
    checkBuiltInFormat("7: {0,time,medium}",   args, availableLocales);
    checkBuiltInFormat("8: {0,time,long}",     args, availableLocales);
    checkBuiltInFormat("9: {0,time,full}",     args, availableLocales);
    checkBuiltInFormat("10: {0,time,HH:mm}",   args, availableLocales);
    checkBuiltInFormat("11: {0,date}",         args, availableLocales);
    checkBuiltInFormat("12: {0,time}",         args, availableLocales);
}
 
Example 4
Source File: ExtendedMessageFormatTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test the built in date/time formats
 */
@Test
public void testBuiltInDateTimeFormat() {
    Calendar cal = Calendar.getInstance();
    cal.set(2007, Calendar.JANUARY, 23, 18, 33, 05);
    Object[] args = new Object[] {cal.getTime()};
    Locale[] availableLocales = DateFormat.getAvailableLocales();

    checkBuiltInFormat("1: {0,date,short}",    args, availableLocales);
    checkBuiltInFormat("2: {0,date,medium}",   args, availableLocales);
    checkBuiltInFormat("3: {0,date,long}",     args, availableLocales);
    checkBuiltInFormat("4: {0,date,full}",     args, availableLocales);
    checkBuiltInFormat("5: {0,date,d MMM yy}", args, availableLocales);
    checkBuiltInFormat("6: {0,time,short}",    args, availableLocales);
    checkBuiltInFormat("7: {0,time,medium}",   args, availableLocales);
    checkBuiltInFormat("8: {0,time,long}",     args, availableLocales);
    checkBuiltInFormat("9: {0,time,full}",     args, availableLocales);
    checkBuiltInFormat("10: {0,time,HH:mm}",   args, availableLocales);
    checkBuiltInFormat("11: {0,date}",         args, availableLocales);
    checkBuiltInFormat("12: {0,time}",         args, availableLocales);
}
 
Example 5
Source File: ExtendedMessageFormatTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public void testOverriddenBuiltinFormat() {
    Calendar cal = Calendar.getInstance();
    cal.set(2007, Calendar.JANUARY, 23);
    Object[] args = new Object[] {cal.getTime()};
    Locale[] availableLocales = DateFormat.getAvailableLocales();
    Map<String, ? extends FormatFactory> registry = Collections.singletonMap("date", new OverrideShortDateFormatFactory());

    //check the non-overridden builtins:
    checkBuiltInFormat("1: {0,date}", registry,          args, availableLocales);
    checkBuiltInFormat("2: {0,date,medium}", registry,   args, availableLocales);
    checkBuiltInFormat("3: {0,date,long}", registry,     args, availableLocales);
    checkBuiltInFormat("4: {0,date,full}", registry,     args, availableLocales);
    checkBuiltInFormat("5: {0,date,d MMM yy}", registry, args, availableLocales);

    //check the overridden format:
    for (int i = -1; i < availableLocales.length; i++) {
        Locale locale = i < 0 ? null : availableLocales[i];
        MessageFormat dateDefault = createMessageFormat("{0,date}", locale);
        String pattern = "{0,date,short}";
        ExtendedMessageFormat dateShort = new ExtendedMessageFormat(pattern, locale, registry);
        assertEquals("overridden date,short format", dateDefault.format(args), dateShort.format(args));
        assertEquals("overridden date,short pattern", pattern, dateShort.toPattern());
    }
}
 
Example 6
Source File: Bug8141243.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    TimeZone UTC = TimeZone.getTimeZone("UTC");
    TimeZone initTz = TimeZone.getDefault();

    List<String> errors = new ArrayList<>();
    try {
        TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
        for (Locale locale : DateFormat.getAvailableLocales()) {
            // exclude any locales which localize "UTC".
            String utc = UTC.getDisplayName(false, SHORT, locale);
            if (!"UTC".equals(utc)) {
                System.out.println("Skipping " + locale + " due to localized UTC name: " + utc);
                continue;
            }
            SimpleDateFormat fmt = new SimpleDateFormat("z", locale);
            try {
                Date date = fmt.parse("UTC");
                // Parsed one may not exactly be UTC. Universal, UCT, etc. are equivalents.
                if (!fmt.getTimeZone().getID().matches("(Etc/)?(UTC|Universal|UCT|Zulu)")) {
                    errors.add("timezone: " + fmt.getTimeZone().getID()
                               + ", locale: " + locale);
                }
            } catch (ParseException e) {
                errors.add("parse exception: " + e + ", locale: " + locale);
            }
        }
    } finally {
        // Restore the default time zone
        TimeZone.setDefault(initTz);
    }

    if (!errors.isEmpty()) {
        System.out.println("Got unexpected results:");
        for (String s : errors) {
            System.out.println("    " + s);
        }
        throw new RuntimeException("Test failed.");
    } else {
        System.out.println("Test passed.");
    }
}
 
Example 7
Source File: Bug8141243.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    TimeZone UTC = TimeZone.getTimeZone("UTC");
    TimeZone initTz = TimeZone.getDefault();

    List<String> errors = new ArrayList<>();
    try {
        TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
        for (Locale locale : DateFormat.getAvailableLocales()) {
            // exclude any locales which localize "UTC".
            String utc = UTC.getDisplayName(false, SHORT, locale);
            if (!"UTC".equals(utc)) {
                System.out.println("Skipping " + locale + " due to localized UTC name: " + utc);
                continue;
            }
            SimpleDateFormat fmt = new SimpleDateFormat("z", locale);
            try {
                Date date = fmt.parse("UTC");
                // Parsed one may not exactly be UTC. Universal, UCT, etc. are equivalents.
                if (!fmt.getTimeZone().getID().matches("(Etc/)?(UTC|Universal|UCT|Zulu)")) {
                    errors.add("timezone: " + fmt.getTimeZone().getID()
                               + ", locale: " + locale);
                }
            } catch (ParseException e) {
                errors.add("parse exception: " + e + ", locale: " + locale);
            }
        }
    } finally {
        // Restore the default time zone
        TimeZone.setDefault(initTz);
    }

    if (!errors.isEmpty()) {
        System.out.println("Got unexpected results:");
        for (String s : errors) {
            System.out.println("    " + s);
        }
        throw new RuntimeException("Test failed.");
    } else {
        System.out.println("Test passed.");
    }
}
 
Example 8
Source File: Bug8141243.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    TimeZone UTC = TimeZone.getTimeZone("UTC");
    TimeZone initTz = TimeZone.getDefault();

    List<String> errors = new ArrayList<>();
    try {
        TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
        for (Locale locale : DateFormat.getAvailableLocales()) {
            // exclude any locales which localize "UTC".
            String utc = UTC.getDisplayName(false, SHORT, locale);
            if (!"UTC".equals(utc)) {
                System.out.println("Skipping " + locale + " due to localized UTC name: " + utc);
                continue;
            }
            SimpleDateFormat fmt = new SimpleDateFormat("z", locale);
            try {
                Date date = fmt.parse("UTC");
                // Parsed one may not exactly be UTC. Universal, UCT, etc. are equivalents.
                if (!fmt.getTimeZone().getID().matches("(Etc/)?(UTC|Universal|UCT|Zulu)")) {
                    errors.add("timezone: " + fmt.getTimeZone().getID()
                               + ", locale: " + locale);
                }
            } catch (ParseException e) {
                errors.add("parse exception: " + e + ", locale: " + locale);
            }
        }
    } finally {
        // Restore the default time zone
        TimeZone.setDefault(initTz);
    }

    if (!errors.isEmpty()) {
        System.out.println("Got unexpected results:");
        for (String s : errors) {
            System.out.println("    " + s);
        }
        throw new RuntimeException("Test failed.");
    } else {
        System.out.println("Test passed.");
    }
}
 
Example 9
Source File: Bug8141243.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    TimeZone UTC = TimeZone.getTimeZone("UTC");
    TimeZone initTz = TimeZone.getDefault();

    List<String> errors = new ArrayList<>();
    try {
        TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
        for (Locale locale : DateFormat.getAvailableLocales()) {
            // exclude any locales which localize "UTC".
            String utc = UTC.getDisplayName(false, SHORT, locale);
            if (!"UTC".equals(utc)) {
                System.out.println("Skipping " + locale + " due to localized UTC name: " + utc);
                continue;
            }
            SimpleDateFormat fmt = new SimpleDateFormat("z", locale);
            try {
                Date date = fmt.parse("UTC");
                // Parsed one may not exactly be UTC. Universal, UCT, etc. are equivalents.
                if (!fmt.getTimeZone().getID().matches("(Etc/)?(UTC|Universal|UCT|Zulu)")) {
                    errors.add("timezone: " + fmt.getTimeZone().getID()
                               + ", locale: " + locale);
                }
            } catch (ParseException e) {
                errors.add("parse exception: " + e + ", locale: " + locale);
            }
        }
    } finally {
        // Restore the default time zone
        TimeZone.setDefault(initTz);
    }

    if (!errors.isEmpty()) {
        System.out.println("Got unexpected results:");
        for (String s : errors) {
            System.out.println("    " + s);
        }
        throw new RuntimeException("Test failed.");
    } else {
        System.out.println("Test passed.");
    }
}
 
Example 10
Source File: SimpleDateTimeFormatStyleProvider.java    From threetenbp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Locale[] getAvailableLocales() {
    return DateFormat.getAvailableLocales();
}
 
Example 11
Source File: Calendar.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns an array of all locales for which the <code>getInstance</code>
 * methods of this class can return localized instances.
 * The array returned must contain at least a <code>Locale</code>
 * instance equal to {@link java.util.Locale#US Locale.US}.
 *
 * @return An array of locales for which localized
 *         <code>Calendar</code> instances are available.
 */
public static synchronized Locale[] getAvailableLocales()
{
    return DateFormat.getAvailableLocales();
}
 
Example 12
Source File: Calendar.java    From jdk1.8-source-analysis with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an array of all locales for which the <code>getInstance</code>
 * methods of this class can return localized instances.
 * The array returned must contain at least a <code>Locale</code>
 * instance equal to {@link java.util.Locale#US Locale.US}.
 *
 * @return An array of locales for which localized
 *         <code>Calendar</code> instances are available.
 */
public static synchronized Locale[] getAvailableLocales()
{
    return DateFormat.getAvailableLocales();
}
 
Example 13
Source File: Calendar.java    From Bytecoder with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an array of all locales for which the {@code getInstance}
 * methods of this class can return localized instances.
 * The array returned must contain at least a {@code Locale}
 * instance equal to {@link java.util.Locale#US Locale.US}.
 *
 * @return An array of locales for which localized
 *         {@code Calendar} instances are available.
 */
public static synchronized Locale[] getAvailableLocales()
{
    return DateFormat.getAvailableLocales();
}
 
Example 14
Source File: Calendar.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns an array of all locales for which the <code>getInstance</code>
 * methods of this class can return localized instances.
 * The array returned must contain at least a <code>Locale</code>
 * instance equal to {@link java.util.Locale#US Locale.US}.
 *
 * @return An array of locales for which localized
 *         <code>Calendar</code> instances are available.
 */
public static synchronized Locale[] getAvailableLocales()
{
    return DateFormat.getAvailableLocales();
}
 
Example 15
Source File: Calendar.java    From j2objc with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an array of all locales for which the <code>getInstance</code>
 * methods of this class can return localized instances.
 * The array returned must contain at least a <code>Locale</code>
 * instance equal to {@link java.util.Locale#US Locale.US}.
 *
 * @return An array of locales for which localized
 *         <code>Calendar</code> instances are available.
 */
public static synchronized Locale[] getAvailableLocales()
{
    return DateFormat.getAvailableLocales();
}
 
Example 16
Source File: Calendar.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns an array of all locales for which the <code>getInstance</code>
 * methods of this class can return localized instances.
 * The array returned must contain at least a <code>Locale</code>
 * instance equal to {@link java.util.Locale#US Locale.US}.
 *
 * @return An array of locales for which localized
 *         <code>Calendar</code> instances are available.
 */
public static synchronized Locale[] getAvailableLocales()
{
    return DateFormat.getAvailableLocales();
}
 
Example 17
Source File: Calendar.java    From jdk8u_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns an array of all locales for which the <code>getInstance</code>
 * methods of this class can return localized instances.
 * The array returned must contain at least a <code>Locale</code>
 * instance equal to {@link java.util.Locale#US Locale.US}.
 *
 * @return An array of locales for which localized
 *         <code>Calendar</code> instances are available.
 */
public static synchronized Locale[] getAvailableLocales()
{
    return DateFormat.getAvailableLocales();
}
 
Example 18
Source File: Calendar.java    From jdk-1.7-annotated with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an array of all locales for which the <code>getInstance</code>
 * methods of this class can return localized instances.
 * The array returned must contain at least a <code>Locale</code>
 * instance equal to {@link java.util.Locale#US Locale.US}.
 *
 * @return An array of locales for which localized
 *         <code>Calendar</code> instances are available.
 */
public static synchronized Locale[] getAvailableLocales()
{
    return DateFormat.getAvailableLocales();
}
 
Example 19
Source File: Calendar.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns an array of all locales for which the <code>getInstance</code>
 * methods of this class can return localized instances.
 * The array returned must contain at least a <code>Locale</code>
 * instance equal to {@link java.util.Locale#US Locale.US}.
 *
 * @return An array of locales for which localized
 *         <code>Calendar</code> instances are available.
 */
public static synchronized Locale[] getAvailableLocales()
{
    return DateFormat.getAvailableLocales();
}
 
Example 20
Source File: Calendar.java    From jdk8u-dev-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns an array of all locales for which the <code>getInstance</code>
 * methods of this class can return localized instances.
 * The array returned must contain at least a <code>Locale</code>
 * instance equal to {@link java.util.Locale#US Locale.US}.
 *
 * @return An array of locales for which localized
 *         <code>Calendar</code> instances are available.
 */
public static synchronized Locale[] getAvailableLocales()
{
    return DateFormat.getAvailableLocales();
}