Java Code Examples for java.time.chrono.Chronology#getAvailableChronologies()
The following examples show how to use
java.time.chrono.Chronology#getAvailableChronologies() .
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: TestChronologyPerf.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test public void test_chronologyGetAvailablePerf() { long start = System.nanoTime(); Set<Chronology> chronos = Chronology.getAvailableChronologies(); long end = System.nanoTime(); Duration d = Duration.of(end - start, ChronoUnit.NANOS); System.out.printf(" Cold Duration of Chronology.getAvailableChronologies(): %s%n", d); start = System.nanoTime(); chronos = Chronology.getAvailableChronologies(); end = System.nanoTime(); d = Duration.of(end - start, ChronoUnit.NANOS); System.out.printf(" Warm Duration of Chronology.getAvailableChronologies(): %s%n", d); start = System.nanoTime(); HijrahChronology.INSTANCE.date(1434, 1, 1); end = System.nanoTime(); d = Duration.of(end - start, ChronoUnit.NANOS); System.out.printf(" Warm Duration of HijrahDate.date(1434, 1, 1): %s%n", d); }
Example 2
Source File: TestChronologyPerf.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Test public void test_chronologyGetAvailablePerf() { long start = System.nanoTime(); Set<Chronology> chronos = Chronology.getAvailableChronologies(); long end = System.nanoTime(); Duration d = Duration.of(end - start, ChronoUnit.NANOS); System.out.printf(" Cold Duration of Chronology.getAvailableChronologies(): %s%n", d); start = System.nanoTime(); chronos = Chronology.getAvailableChronologies(); end = System.nanoTime(); d = Duration.of(end - start, ChronoUnit.NANOS); System.out.printf(" Warm Duration of Chronology.getAvailableChronologies(): %s%n", d); start = System.nanoTime(); HijrahChronology.INSTANCE.date(1434, 1, 1); end = System.nanoTime(); d = Duration.of(end - start, ChronoUnit.NANOS); System.out.printf(" Warm Duration of HijrahDate.date(1434, 1, 1): %s%n", d); }
Example 3
Source File: TestExampleCode.java From hottub with GNU General Public License v2.0 | 5 votes |
@Test public void test_chronoPackageExample() { // Print the Thai Buddhist date ChronoLocalDate now1 = Chronology.of("ThaiBuddhist").dateNow(); int day = now1.get(ChronoField.DAY_OF_MONTH); int dow = now1.get(ChronoField.DAY_OF_WEEK); int month = now1.get(ChronoField.MONTH_OF_YEAR); int year = now1.get(ChronoField.YEAR); System.out.printf(" Today is %s %s %d-%s-%d%n", now1.getChronology().getId(), dow, day, month, year); // Enumerate the list of available calendars and print today for each Set<Chronology> chronos = Chronology.getAvailableChronologies(); for (Chronology chrono : chronos) { ChronoLocalDate date = chrono.dateNow(); System.out.printf(" %20s: %s%n", chrono.getId(), date.toString()); } // Print today's date and the last day of the year for the Thai Buddhist Calendar. ChronoLocalDate first = now1 .with(ChronoField.DAY_OF_MONTH, 1) .with(ChronoField.MONTH_OF_YEAR, 1); ChronoLocalDate last = first .plus(1, ChronoUnit.YEARS) .minus(1, ChronoUnit.DAYS); System.out.printf(" %s: 1st of year: %s; end of year: %s%n", last.getChronology().getId(), first, last); }
Example 4
Source File: TCKChronology.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Test public void test_calendar_list() { Set<Chronology> chronos = Chronology.getAvailableChronologies(); assertNotNull(chronos, "Required list of calendars must be non-null"); for (Chronology chrono : chronos) { Chronology lookup = Chronology.of(chrono.getId()); assertNotNull(lookup, "Required calendar not found: " + chrono); } assertEquals(chronos.size() >= data_of_calendars().length, true, "Chronology.getAvailableChronologies().size = " + chronos.size() + ", expected >= " + data_of_calendars().length); }
Example 5
Source File: TestExampleCode.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test public void test_chronoPackageExample() { // Print the Thai Buddhist date ChronoLocalDate now1 = Chronology.of("ThaiBuddhist").dateNow(); int day = now1.get(ChronoField.DAY_OF_MONTH); int dow = now1.get(ChronoField.DAY_OF_WEEK); int month = now1.get(ChronoField.MONTH_OF_YEAR); int year = now1.get(ChronoField.YEAR); System.out.printf(" Today is %s %s %d-%s-%d%n", now1.getChronology().getId(), dow, day, month, year); // Enumerate the list of available calendars and print today for each Set<Chronology> chronos = Chronology.getAvailableChronologies(); for (Chronology chrono : chronos) { ChronoLocalDate date = chrono.dateNow(); System.out.printf(" %20s: %s%n", chrono.getId(), date.toString()); } // Print today's date and the last day of the year for the Thai Buddhist Calendar. ChronoLocalDate first = now1 .with(ChronoField.DAY_OF_MONTH, 1) .with(ChronoField.MONTH_OF_YEAR, 1); ChronoLocalDate last = first .plus(1, ChronoUnit.YEARS) .minus(1, ChronoUnit.DAYS); System.out.printf(" %s: 1st of year: %s; end of year: %s%n", last.getChronology().getId(), first, last); }
Example 6
Source File: TCKChronology.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Test lookup by calendarType of each chronology. * Verify that the calendar can be found by {@link java.time.chrono.Chronology#ofLocale}. */ @Test public void test_ofLocaleByType() { // Test that all available chronologies can be successfully found using ofLocale Set<Chronology> chronos = Chronology.getAvailableChronologies(); for (Chronology chrono : chronos) { Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA"); builder.setUnicodeLocaleKeyword("ca", chrono.getCalendarType()); Locale locale = builder.build(); assertEquals(Chronology.ofLocale(locale), chrono, "Lookup by type"); } }
Example 7
Source File: TCKChronology.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "calendarNameAndType") public void test_required_calendars(String chronoId, String calendarSystemType) { Chronology chrono = Chronology.of(chronoId); assertNotNull(chrono, "Required calendar not found by ID: " + chronoId); chrono = Chronology.of(calendarSystemType); assertNotNull(chrono, "Required calendar not found by type: " + chronoId); Set<Chronology> cals = Chronology.getAvailableChronologies(); assertTrue(cals.contains(chrono), "Required calendar not found in set of available calendars"); }
Example 8
Source File: DateTimeFormatterBuilder.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Override public int parse(DateTimeParseContext context, CharSequence text, int position) { // simple looping parser to find the chronology if (position < 0 || position > text.length()) { throw new IndexOutOfBoundsException(); } Set<Chronology> chronos = Chronology.getAvailableChronologies(); Chronology bestMatch = null; int matchLen = -1; for (Chronology chrono : chronos) { String name; if (textStyle == null) { name = chrono.getId(); } else { name = getChronologyName(chrono, context.getLocale()); } int nameLen = name.length(); if (nameLen > matchLen && context.subSequenceEquals(text, position, name, 0, nameLen)) { bestMatch = chrono; matchLen = nameLen; } } if (bestMatch == null) { return ~position; } context.setParsed(bestMatch); return position + matchLen; }
Example 9
Source File: TCKChronology.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Test lookup by calendarType of each chronology. * Verify that the calendar can be found by {@link java.time.chrono.Chronology#ofLocale}. */ @Test public void test_ofLocaleByType() { // Test that all available chronologies can be successfully found using ofLocale Set<Chronology> chronos = Chronology.getAvailableChronologies(); for (Chronology chrono : chronos) { Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA"); builder.setUnicodeLocaleKeyword("ca", chrono.getCalendarType()); Locale locale = builder.build(); assertEquals(Chronology.ofLocale(locale), chrono, "Lookup by type"); } }
Example 10
Source File: TestExampleCode.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Test public void test_chronoPackageExample() { // Print the Thai Buddhist date ChronoLocalDate now1 = Chronology.of("ThaiBuddhist").dateNow(); int day = now1.get(ChronoField.DAY_OF_MONTH); int dow = now1.get(ChronoField.DAY_OF_WEEK); int month = now1.get(ChronoField.MONTH_OF_YEAR); int year = now1.get(ChronoField.YEAR); System.out.printf(" Today is %s %s %d-%s-%d%n", now1.getChronology().getId(), dow, day, month, year); // Enumerate the list of available calendars and print today for each Set<Chronology> chronos = Chronology.getAvailableChronologies(); for (Chronology chrono : chronos) { ChronoLocalDate date = chrono.dateNow(); System.out.printf(" %20s: %s%n", chrono.getId(), date.toString()); } // Print today's date and the last day of the year for the Thai Buddhist Calendar. ChronoLocalDate first = now1 .with(ChronoField.DAY_OF_MONTH, 1) .with(ChronoField.MONTH_OF_YEAR, 1); ChronoLocalDate last = first .plus(1, ChronoUnit.YEARS) .minus(1, ChronoUnit.DAYS); System.out.printf(" %s: 1st of year: %s; end of year: %s%n", last.getChronology().getId(), first, last); }
Example 11
Source File: TestExampleCode.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Test public void test_calendarPackageExample() { // Enumerate the list of available calendars and print today for each Set<Chronology> chronos = Chronology.getAvailableChronologies(); for (Chronology chrono : chronos) { ChronoLocalDate date = chrono.dateNow(); System.out.printf(" %20s: %s%n", chrono.getId(), date.toString()); } // Print the Thai Buddhist date ThaiBuddhistDate now1 = ThaiBuddhistDate.now(); int day = now1.get(ChronoField.DAY_OF_MONTH); int dow = now1.get(ChronoField.DAY_OF_WEEK); int month = now1.get(ChronoField.MONTH_OF_YEAR); int year = now1.get(ChronoField.YEAR); System.out.printf(" Today is %s %s %d-%s-%d%n", now1.getChronology().getId(), dow, day, month, year); // Print today's date and the last day of the year for the Thai Buddhist Calendar. ThaiBuddhistDate first = now1 .with(ChronoField.DAY_OF_MONTH, 1) .with(ChronoField.MONTH_OF_YEAR, 1); ThaiBuddhistDate last = first .plus(1, ChronoUnit.YEARS) .minus(1, ChronoUnit.DAYS); System.out.printf(" %s: 1st of year: %s; end of year: %s%n", last.getChronology().getId(), first, last); }
Example 12
Source File: TCKChronology.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test public void test_calendar_list() { Set<Chronology> chronos = Chronology.getAvailableChronologies(); assertNotNull(chronos, "Required list of calendars must be non-null"); for (Chronology chrono : chronos) { Chronology lookup = Chronology.of(chrono.getId()); assertNotNull(lookup, "Required calendar not found: " + chrono); } assertEquals(chronos.size() >= data_of_calendars().length, true, "Chronology.getAvailableChronologies().size = " + chronos.size() + ", expected >= " + data_of_calendars().length); }
Example 13
Source File: DateTimeFormatterBuilder.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Override public int parse(DateTimeParseContext context, CharSequence text, int position) { // simple looping parser to find the chronology if (position < 0 || position > text.length()) { throw new IndexOutOfBoundsException(); } Set<Chronology> chronos = Chronology.getAvailableChronologies(); Chronology bestMatch = null; int matchLen = -1; for (Chronology chrono : chronos) { String name; if (textStyle == null) { name = chrono.getId(); } else { name = getChronologyName(chrono, context.getLocale()); } int nameLen = name.length(); if (nameLen > matchLen && context.subSequenceEquals(text, position, name, 0, nameLen)) { bestMatch = chrono; matchLen = nameLen; } } if (bestMatch == null) { return ~position; } context.setParsed(bestMatch); return position + matchLen; }
Example 14
Source File: TestExampleCode.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_chronoPackageExample() { // Print the Thai Buddhist date ChronoLocalDate now1 = Chronology.of("ThaiBuddhist").dateNow(); int day = now1.get(ChronoField.DAY_OF_MONTH); int dow = now1.get(ChronoField.DAY_OF_WEEK); int month = now1.get(ChronoField.MONTH_OF_YEAR); int year = now1.get(ChronoField.YEAR); System.out.printf(" Today is %s %s %d-%s-%d%n", now1.getChronology().getId(), dow, day, month, year); // Enumerate the list of available calendars and print today for each Set<Chronology> chronos = Chronology.getAvailableChronologies(); for (Chronology chrono : chronos) { ChronoLocalDate date = chrono.dateNow(); System.out.printf(" %20s: %s%n", chrono.getId(), date.toString()); } // Print today's date and the last day of the year for the Thai Buddhist Calendar. ChronoLocalDate first = now1 .with(ChronoField.DAY_OF_MONTH, 1) .with(ChronoField.MONTH_OF_YEAR, 1); ChronoLocalDate last = first .plus(1, ChronoUnit.YEARS) .minus(1, ChronoUnit.DAYS); System.out.printf(" %s: 1st of year: %s; end of year: %s%n", last.getChronology().getId(), first, last); }
Example 15
Source File: TCKChronology.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "calendarNameAndType") public void test_required_calendars(String chronoId, String calendarSystemType) { Chronology chrono = Chronology.of(chronoId); assertNotNull(chrono, "Required calendar not found by ID: " + chronoId); chrono = Chronology.of(calendarSystemType); assertNotNull(chrono, "Required calendar not found by type: " + chronoId); Set<Chronology> cals = Chronology.getAvailableChronologies(); assertTrue(cals.contains(chrono), "Required calendar not found in set of available calendars"); }
Example 16
Source File: DateTimeFormatterBuilder.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Override public int parse(DateTimeParseContext context, CharSequence text, int position) { // simple looping parser to find the chronology if (position < 0 || position > text.length()) { throw new IndexOutOfBoundsException(); } Set<Chronology> chronos = Chronology.getAvailableChronologies(); Chronology bestMatch = null; int matchLen = -1; for (Chronology chrono : chronos) { String name; if (textStyle == null) { name = chrono.getId(); } else { name = getChronologyName(chrono, context.getLocale()); } int nameLen = name.length(); if (nameLen > matchLen && context.subSequenceEquals(text, position, name, 0, nameLen)) { bestMatch = chrono; matchLen = nameLen; } } if (bestMatch == null) { return ~position; } context.setParsed(bestMatch); return position + matchLen; }
Example 17
Source File: TCKChronology.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * Test lookup by calendarType of each chronology. * Verify that the calendar can be found by {@link java.time.chrono.Chronology#ofLocale}. */ @Test public void test_ofLocaleByType() { // Test that all available chronologies can be successfully found using ofLocale Set<Chronology> chronos = Chronology.getAvailableChronologies(); for (Chronology chrono : chronos) { Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA"); builder.setUnicodeLocaleKeyword("ca", chrono.getCalendarType()); Locale locale = builder.build(); assertEquals(Chronology.ofLocale(locale), chrono, "Lookup by type"); } }
Example 18
Source File: DateTimeFormatterBuilder.java From JDKSourceCode1.8 with MIT License | 5 votes |
@Override public int parse(DateTimeParseContext context, CharSequence text, int position) { // simple looping parser to find the chronology if (position < 0 || position > text.length()) { throw new IndexOutOfBoundsException(); } Set<Chronology> chronos = Chronology.getAvailableChronologies(); Chronology bestMatch = null; int matchLen = -1; for (Chronology chrono : chronos) { String name; if (textStyle == null) { name = chrono.getId(); } else { name = getChronologyName(chrono, context.getLocale()); } int nameLen = name.length(); if (nameLen > matchLen && context.subSequenceEquals(text, position, name, 0, nameLen)) { bestMatch = chrono; matchLen = nameLen; } } if (bestMatch == null) { return ~position; } context.setParsed(bestMatch); return position + matchLen; }
Example 19
Source File: TCKChronology.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Test lookup by calendarType of each chronology. * Verify that the calendar can be found by {@link java.time.chrono.Chronology#ofLocale}. */ @Test public void test_ofLocaleByType() { // Test that all available chronologies can be successfully found using ofLocale Set<Chronology> chronos = Chronology.getAvailableChronologies(); for (Chronology chrono : chronos) { Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA"); builder.setUnicodeLocaleKeyword("ca", chrono.getCalendarType()); Locale locale = builder.build(); assertEquals(Chronology.ofLocale(locale), chrono, "Lookup by type"); } }
Example 20
Source File: TestExampleCode.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Test public void test_calendarPackageExample() { // Enumerate the list of available calendars and print today for each Set<Chronology> chronos = Chronology.getAvailableChronologies(); for (Chronology chrono : chronos) { ChronoLocalDate date = chrono.dateNow(); System.out.printf(" %20s: %s%n", chrono.getId(), date.toString()); } // Print the Thai Buddhist date ThaiBuddhistDate now1 = ThaiBuddhistDate.now(); int day = now1.get(ChronoField.DAY_OF_MONTH); int dow = now1.get(ChronoField.DAY_OF_WEEK); int month = now1.get(ChronoField.MONTH_OF_YEAR); int year = now1.get(ChronoField.YEAR); System.out.printf(" Today is %s %s %d-%s-%d%n", now1.getChronology().getId(), dow, day, month, year); // Print today's date and the last day of the year for the Thai Buddhist Calendar. ThaiBuddhistDate first = now1 .with(ChronoField.DAY_OF_MONTH, 1) .with(ChronoField.MONTH_OF_YEAR, 1); ThaiBuddhistDate last = first .plus(1, ChronoUnit.YEARS) .minus(1, ChronoUnit.DAYS); System.out.printf(" %s: 1st of year: %s; end of year: %s%n", last.getChronology().getId(), first, last); }