Java Code Examples for java.util.Calendar#getAvailableLocales()

The following examples show how to use java.util.Calendar#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: JLocaleChooser.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Default JLocaleChooser constructor.
 */
public JLocaleChooser(JComponent component) {
	super();
	this.component = component;
	addItemListener(this);
	locales = Calendar.getAvailableLocales();
	localeCount = locales.length;

	for (int i = 0; i < localeCount; i++) {
		if (locales[i].getCountry().length() > 0) {
			addItem(locales[i].getDisplayName());
		}
	}

	setLocale(Locale.getDefault());
}
 
Example 2
Source File: JapanEraNameCompatTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testFormatParseEraName() {
    LocalDate date = LocalDate.of(2019, 5, 1);
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MM dd GGGG");
    formatter = formatter.withChronology(JapaneseChronology.INSTANCE);

    int num = 0;
    for (Locale locale : Calendar.getAvailableLocales()) {
        formatter = formatter.withLocale(locale);
        try {
            LocalDate.parse(date.format(formatter), formatter);
        } catch (DateTimeParseException e) {
            // If an array is defined for Japanese eras in java.time resource,
            // but an era entry is missing, format fallback to English name
            // while parse throw DateTimeParseException.
            num++;
            System.out.println("Missing java.time resource data for locale: " + locale);
        }
    }
    if (num > 0) {
        throw new RuntimeException("Missing java.time data for " + num + " locales");
    }
}
 
Example 3
Source File: JapanEraNameCompatTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testFormatParseEraName() {
    LocalDate date = LocalDate.of(2019, 5, 1);
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MM dd GGGG");
    formatter = formatter.withChronology(JapaneseChronology.INSTANCE);

    int num = 0;
    for (Locale locale : Calendar.getAvailableLocales()) {
        formatter = formatter.withLocale(locale);
        try {
            LocalDate.parse(date.format(formatter), formatter);
        } catch (DateTimeParseException e) {
            // If an array is defined for Japanese eras in java.time resource,
            // but an era entry is missing, format fallback to English name
            // while parse throw DateTimeParseException.
            num++;
            System.out.println("Missing java.time resource data for locale: " + locale);
        }
    }
    if (num > 0) {
        throw new RuntimeException("Missing java.time data for " + num + " locales");
    }
}
 
Example 4
Source File: JapanEraNameCompatTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testFormatParseEraName() {
    LocalDate date = LocalDate.of(2019, 5, 1);
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MM dd GGGG");
    formatter = formatter.withChronology(JapaneseChronology.INSTANCE);

    int num = 0;
    for (Locale locale : Calendar.getAvailableLocales()) {
        formatter = formatter.withLocale(locale);
        try {
            LocalDate.parse(date.format(formatter), formatter);
        } catch (DateTimeParseException e) {
            // If an array is defined for Japanese eras in java.time resource,
            // but an era entry is missing, format fallback to English name
            // while parse throw DateTimeParseException.
            num++;
            System.out.println("Missing java.time resource data for locale: " + locale);
        }
    }
    if (num > 0) {
        throw new RuntimeException("Missing java.time data for " + num + " locales");
    }
}
 
Example 5
Source File: JapanEraNameCompatTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testFormatParseEraName() {
    LocalDate date = LocalDate.of(2019, 5, 1);
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MM dd GGGG");
    formatter = formatter.withChronology(JapaneseChronology.INSTANCE);

    int num = 0;
    for (Locale locale : Calendar.getAvailableLocales()) {
        formatter = formatter.withLocale(locale);
        try {
            LocalDate.parse(date.format(formatter), formatter);
        } catch (DateTimeParseException e) {
            // If an array is defined for Japanese eras in java.time resource,
            // but an era entry is missing, format fallback to English name
            // while parse throw DateTimeParseException.
            num++;
            System.out.println("Missing java.time resource data for locale: " + locale);
        }
    }
    if (num > 0) {
        throw new RuntimeException("Missing java.time data for " + num + " locales");
    }
}
 
Example 6
Source File: LocaleEditor.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Default LocaleEditor constructor.
 */
public LocaleEditor() {
	locale = Locale.getDefault();
	locales = Calendar.getAvailableLocales();
	length = locales.length;
	localeStrings = new String[length];
}
 
Example 7
Source File: CalendarTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.Calendar#getAvailableLocales()
 */
public void test_getAvailableLocales() {
    Locale[] locales = Calendar.getAvailableLocales();
    boolean exist = false;
    for (int i = 0; i < locales.length; i++) {
        Locale l = locales[i];
        if (Locale.US.equals(l)) {
            exist = true;
            break;
        }
    }
    assertTrue(exist);
}