Search in sources :

Example 31 with ChronoLocalDate

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

the class TCKChronology method test_MinguoChronology_dateYearDay.

@Test
public void test_MinguoChronology_dateYearDay() {
    Chronology chrono = Chronology.of("Minguo");
    ChronoLocalDate date1 = chrono.dateYearDay(MinguoEra.ROC, 5, 60);
    ChronoLocalDate date2 = chrono.date(MinguoEra.ROC, 5, 2, 29);
    assertEquals(date1, MinguoChronology.INSTANCE.dateYearDay(MinguoEra.ROC, 5, 60));
    assertEquals(date2, MinguoChronology.INSTANCE.dateYearDay(MinguoEra.ROC, 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 32 with ChronoLocalDate

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

the class TCKChronoPeriod method test_addTo_wrongChrono.

@Test(dataProvider = "calendars", expectedExceptions = DateTimeException.class)
public void test_addTo_wrongChrono(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoLocalDate isoDate = LocalDate.of(2000, 1, 1);
    ChronoLocalDate thaiDate = ThaiBuddhistChronology.INSTANCE.date(2000, 1, 1);
    // one of these two will fail
    period.addTo(isoDate);
    period.addTo(thaiDate);
}
Also used : ChronoPeriod(java.time.chrono.ChronoPeriod) ChronoLocalDate(java.time.chrono.ChronoLocalDate) Test(org.testng.annotations.Test)

Example 33 with ChronoLocalDate

use of java.time.chrono.ChronoLocalDate 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 34 with ChronoLocalDate

use of java.time.chrono.ChronoLocalDate 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 35 with ChronoLocalDate

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

the class TCKChronoPeriod method test_subtractFrom_wrongChrono.

@Test(dataProvider = "calendars", expectedExceptions = DateTimeException.class)
public void test_subtractFrom_wrongChrono(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoLocalDate isoDate = LocalDate.of(2000, 1, 1);
    ChronoLocalDate thaiDate = ThaiBuddhistChronology.INSTANCE.date(2000, 1, 1);
    // one of these two will fail
    period.subtractFrom(isoDate);
    period.subtractFrom(thaiDate);
}
Also used : ChronoPeriod(java.time.chrono.ChronoPeriod) ChronoLocalDate(java.time.chrono.ChronoLocalDate) 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