Search in sources :

Example 61 with Chronology

use of java.time.chrono.Chronology in project jdk8u_jdk by JetBrains.

the class TCKChronoLocalDateTime method test_badTemporalFieldChrono.

@Test(dataProvider = "calendars")
public void test_badTemporalFieldChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
        TemporalField adjuster = new FixedTemporalField(cdt2);
        if (chrono != chrono2) {
            try {
                cdt.with(adjuster, 1);
                Assert.fail("TemporalField doWith() should have thrown a ClassCastException" + cdt.getClass() + ", can not be cast to " + cdt2.getClass());
            } catch (ClassCastException cce) {
            // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDateTime<?> result = cdt.with(adjuster, 1);
            assertEquals(result, cdt2, "TemporalField doWith() failed to replace date");
        }
    }
}
Also used : TemporalField(java.time.temporal.TemporalField) HijrahChronology(java.time.chrono.HijrahChronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) MinguoChronology(java.time.chrono.MinguoChronology) JapaneseChronology(java.time.chrono.JapaneseChronology) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 62 with Chronology

use of java.time.chrono.Chronology in project jdk8u_jdk by JetBrains.

the class TCKChronology method test_ofLocaleByType.

/**
     * 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");
    }
}
Also used : Locale(java.util.Locale) HijrahChronology(java.time.chrono.HijrahChronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) MinguoChronology(java.time.chrono.MinguoChronology) JapaneseChronology(java.time.chrono.JapaneseChronology) Test(org.testng.annotations.Test)

Example 63 with Chronology

use of java.time.chrono.Chronology in project jdk8u_jdk by JetBrains.

the class TCKChronology method test_ThaiBuddhistChronology_dateYearDay.

@Test
public void test_ThaiBuddhistChronology_dateYearDay() {
    Chronology chrono = Chronology.of("ThaiBuddhist");
    ChronoLocalDate date1 = chrono.dateYearDay(ThaiBuddhistEra.BE, 2459, 60);
    ChronoLocalDate date2 = chrono.date(ThaiBuddhistEra.BE, 2459, 2, 29);
    assertEquals(date1, ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BE, 2459, 60));
    assertEquals(date2, ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BE, 2459, 60));
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) HijrahChronology(java.time.chrono.HijrahChronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) MinguoChronology(java.time.chrono.MinguoChronology) JapaneseChronology(java.time.chrono.JapaneseChronology) Test(org.testng.annotations.Test)

Example 64 with Chronology

use of java.time.chrono.Chronology in project jdk8u_jdk by JetBrains.

the class TCKChronology method test_epoch.

/**
     * Compute the number of days from the Epoch and compute the date from the number of days.
     */
@Test(dataProvider = "calendarNameAndType")
public void test_epoch(String name, String alias) {
    // a chronology. In practice this is rarely hardcoded
    Chronology chrono = Chronology.of(name);
    ChronoLocalDate date1 = chrono.dateNow();
    long epoch1 = date1.getLong(ChronoField.EPOCH_DAY);
    ChronoLocalDate date2 = date1.with(ChronoField.EPOCH_DAY, epoch1);
    assertEquals(date1, date2, "Date from epoch day is not same date: " + date1 + " != " + date2);
    long epoch2 = date1.getLong(ChronoField.EPOCH_DAY);
    assertEquals(epoch1, epoch2, "Epoch day not the same: " + epoch1 + " != " + epoch2);
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) HijrahChronology(java.time.chrono.HijrahChronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) MinguoChronology(java.time.chrono.MinguoChronology) JapaneseChronology(java.time.chrono.JapaneseChronology) Test(org.testng.annotations.Test)

Example 65 with Chronology

use of java.time.chrono.Chronology in project jdk8u_jdk by JetBrains.

the class TCKChronology method test_required_calendars.

@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");
}
Also used : HijrahChronology(java.time.chrono.HijrahChronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) MinguoChronology(java.time.chrono.MinguoChronology) JapaneseChronology(java.time.chrono.JapaneseChronology) Test(org.testng.annotations.Test)

Aggregations

Chronology (java.time.chrono.Chronology)76 Test (org.testng.annotations.Test)65 IsoChronology (java.time.chrono.IsoChronology)59 ThaiBuddhistChronology (java.time.chrono.ThaiBuddhistChronology)58 MinguoChronology (java.time.chrono.MinguoChronology)54 HijrahChronology (java.time.chrono.HijrahChronology)47 JapaneseChronology (java.time.chrono.JapaneseChronology)46 ChronoLocalDate (java.time.chrono.ChronoLocalDate)29 LocalDate (java.time.LocalDate)21 Locale (java.util.Locale)7 TemporalAmount (java.time.temporal.TemporalAmount)6 TemporalUnit (java.time.temporal.TemporalUnit)6 ZoneId (java.time.ZoneId)5 TemporalAccessor (java.time.temporal.TemporalAccessor)5 Clock (java.time.Clock)4 DateTimeException (java.time.DateTimeException)4 Era (java.time.chrono.Era)4 TemporalField (java.time.temporal.TemporalField)4 ChronoLocalDateTime (java.time.chrono.ChronoLocalDateTime)3 DateTimeFormatter (java.time.format.DateTimeFormatter)3