Search in sources :

Example 6 with ChronoLocalDate

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

the class TCKHijrahChronology method test_InvalidEras.

//-----------------------------------------------------------------------
// Bad Era for Chronology.date(era,...) and Chronology.prolepticYear(Era,...)
//-----------------------------------------------------------------------
@Test
public void test_InvalidEras() {
    // Verify that the eras from every other Chronology are invalid
    for (Chronology chrono : Chronology.getAvailableChronologies()) {
        if (chrono instanceof HijrahChronology) {
            continue;
        }
        List<Era> eras = chrono.eras();
        for (Era era : eras) {
            try {
                ChronoLocalDate date = HijrahChronology.INSTANCE.date(era, 1, 1, 1);
                fail("HijrahChronology.date did not throw ClassCastException for Era: " + era);
            } catch (ClassCastException cex) {
                // ignore expected exception
                ;
            }
            try {
                @SuppressWarnings("unused") int year = HijrahChronology.INSTANCE.prolepticYear(era, 1);
                fail("HijrahChronology.prolepticYear did not throw ClassCastException for Era: " + era);
            } catch (ClassCastException cex) {
                // ignore expected exception
                ;
            }
        }
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) Era(java.time.chrono.Era) HijrahEra(java.time.chrono.HijrahEra) HijrahChronology(java.time.chrono.HijrahChronology) HijrahChronology(java.time.chrono.HijrahChronology) Chronology(java.time.chrono.Chronology) IsoChronology(java.time.chrono.IsoChronology) Test(org.testng.annotations.Test)

Example 7 with ChronoLocalDate

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

the class TCKChronology method test_IsoChronology_dateYearDay.

@Test
public void test_IsoChronology_dateYearDay() {
    Chronology chrono = Chronology.of("ISO");
    ChronoLocalDate date1 = chrono.dateYearDay(IsoEra.CE, 5, 60);
    ChronoLocalDate date2 = chrono.date(IsoEra.CE, 5, 3, 1);
    assertEquals(date1, IsoChronology.INSTANCE.dateYearDay(IsoEra.CE, 5, 60));
    assertEquals(date2, IsoChronology.INSTANCE.dateYearDay(IsoEra.CE, 5, 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 8 with ChronoLocalDate

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

the class TCKChronoPeriod method test_subtractFrom.

@Test(dataProvider = "calendars")
public void test_subtractFrom(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoLocalDate date = chrono.dateNow();
    Temporal result = period.subtractFrom(date);
    assertEquals(result, date.minus(14, MONTHS).minus(3, DAYS));
}
Also used : ChronoPeriod(java.time.chrono.ChronoPeriod) ChronoLocalDate(java.time.chrono.ChronoLocalDate) Temporal(java.time.temporal.Temporal) Test(org.testng.annotations.Test)

Example 9 with ChronoLocalDate

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

the class TCKChronology method test_dateEpochDay.

@Test(dataProvider = "calendarNameAndType")
public void test_dateEpochDay(String name, String alias) {
    Chronology chrono = Chronology.of(name);
    ChronoLocalDate date = chrono.dateNow();
    long epochDay = date.getLong(ChronoField.EPOCH_DAY);
    ChronoLocalDate test = chrono.dateEpochDay(epochDay);
    assertEquals(test, date);
}
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 10 with ChronoLocalDate

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

the class TCKChronology method test_HijrahChronology_dateYearDay.

//-----------------------------------------------------------------------
// dateYearDay() and date()
//-----------------------------------------------------------------------
@Test
public void test_HijrahChronology_dateYearDay() {
    Chronology chrono = Chronology.of("Hijrah");
    ChronoLocalDate date1 = chrono.dateYearDay(HijrahEra.AH, 1434, 178);
    ChronoLocalDate date2 = chrono.date(HijrahEra.AH, 1434, 7, 1);
    assertEquals(date1, HijrahChronology.INSTANCE.dateYearDay(HijrahEra.AH, 1434, 178));
    assertEquals(date2, HijrahChronology.INSTANCE.dateYearDay(HijrahEra.AH, 1434, 178));
}
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)

Aggregations

ChronoLocalDate (java.time.chrono.ChronoLocalDate)43 Test (org.testng.annotations.Test)34 Chronology (java.time.chrono.Chronology)28 IsoChronology (java.time.chrono.IsoChronology)19 ThaiBuddhistChronology (java.time.chrono.ThaiBuddhistChronology)18 HijrahChronology (java.time.chrono.HijrahChronology)17 MinguoChronology (java.time.chrono.MinguoChronology)17 JapaneseChronology (java.time.chrono.JapaneseChronology)15 LocalDate (java.time.LocalDate)10 DateTimeException (java.time.DateTimeException)5 ChronoPeriod (java.time.chrono.ChronoPeriod)4 Era (java.time.chrono.Era)4 DateTimeFormatter (java.time.format.DateTimeFormatter)3 TemporalAccessor (java.time.temporal.TemporalAccessor)3 TemporalField (java.time.temporal.TemporalField)3 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)2 ThaiBuddhistDate (java.time.chrono.ThaiBuddhistDate)2 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)2 Temporal (java.time.temporal.Temporal)2 TemporalAmount (java.time.temporal.TemporalAmount)2