Search in sources :

Example 46 with Chronology

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

the class TCKChronoZonedDateTime method test_zonedDateTime_comparisons.

//-----------------------------------------------------------------------
// isBefore, isAfter, isEqual, timeLineOrder()  test a Chronology against the other Chronos
//-----------------------------------------------------------------------
@Test(dataProvider = "calendars")
public void test_zonedDateTime_comparisons(Chronology chrono) {
    List<ChronoZonedDateTime<?>> dates = new ArrayList<>();
    ChronoZonedDateTime<?> date = chrono.date(LocalDate.of(2013, 1, 1)).atTime(LocalTime.MIN).atZone(ZoneOffset.UTC);
    // Insert dates in order, no duplicates
    dates.add(date.minus(1, ChronoUnit.YEARS));
    dates.add(date.minus(1, ChronoUnit.MONTHS));
    dates.add(date.minus(1, ChronoUnit.WEEKS));
    dates.add(date.minus(1, ChronoUnit.DAYS));
    dates.add(date.minus(1, ChronoUnit.HOURS));
    dates.add(date.minus(1, ChronoUnit.MINUTES));
    dates.add(date.minus(1, ChronoUnit.SECONDS));
    dates.add(date.minus(1, ChronoUnit.NANOS));
    dates.add(date);
    dates.add(date.plus(1, ChronoUnit.NANOS));
    dates.add(date.plus(1, ChronoUnit.SECONDS));
    dates.add(date.plus(1, ChronoUnit.MINUTES));
    dates.add(date.plus(1, ChronoUnit.HOURS));
    dates.add(date.plus(1, ChronoUnit.DAYS));
    dates.add(date.plus(1, ChronoUnit.WEEKS));
    dates.add(date.plus(1, ChronoUnit.MONTHS));
    dates.add(date.plus(1, ChronoUnit.YEARS));
    // Check these dates against the corresponding dates for every calendar
    for (Chronology[] clist : data_of_calendars()) {
        List<ChronoZonedDateTime<?>> otherDates = new ArrayList<>();
        //clist[0];
        Chronology chrono2 = IsoChronology.INSTANCE;
        for (ChronoZonedDateTime<?> d : dates) {
            otherDates.add(chrono2.date(d).atTime(d.toLocalTime()).atZone(d.getZone()));
        }
        // Now compare  the sequence of original dates with the sequence of converted dates
        for (int i = 0; i < dates.size(); i++) {
            ChronoZonedDateTime<?> a = dates.get(i);
            for (int j = 0; j < otherDates.size(); j++) {
                ChronoZonedDateTime<?> b = otherDates.get(j);
                int cmp = ChronoZonedDateTime.timeLineOrder().compare(a, b);
                if (i < j) {
                    assertTrue(cmp < 0, a + " compare " + b);
                    assertEquals(a.isBefore(b), true, a + " isBefore " + b);
                    assertEquals(a.isAfter(b), false, a + " ifAfter " + b);
                    assertEquals(a.isEqual(b), false, a + " isEqual " + b);
                } else if (i > j) {
                    assertTrue(cmp > 0, a + " compare " + b);
                    assertEquals(a.isBefore(b), false, a + " isBefore " + b);
                    assertEquals(a.isAfter(b), true, a + " ifAfter " + b);
                    assertEquals(a.isEqual(b), false, a + " isEqual " + b);
                } else {
                    assertTrue(cmp == 0, a + " compare " + b);
                    assertEquals(a.isBefore(b), false, a + " isBefore " + b);
                    assertEquals(a.isAfter(b), false, a + " ifAfter " + b);
                    assertEquals(a.isEqual(b), true, a + " isEqual " + b);
                }
            }
        }
    }
}
Also used : ChronoZonedDateTime(java.time.chrono.ChronoZonedDateTime) ArrayList(java.util.ArrayList) 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 47 with Chronology

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

the class TCKChronoZonedDateTime method test_badPlusTemporalUnitChrono.

@Test(dataProvider = "calendars")
public void test_badPlusTemporalUnitChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
        TemporalUnit adjuster = new FixedTemporalUnit(czdt2);
        if (chrono != chrono2) {
            try {
                czdt.plus(1, adjuster);
                Assert.fail("TemporalUnit.doPlus plus should have thrown a ClassCastException, " + czdt + " can not be cast to " + czdt2);
            } catch (ClassCastException cce) {
            // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoZonedDateTime<?> result = czdt.plus(1, adjuster);
            assertEquals(result, czdt2, "WithAdjuster failed to replace date");
        }
    }
}
Also used : TemporalUnit(java.time.temporal.TemporalUnit) 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 48 with Chronology

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

the class TCKChronoLocalDate method test_badWithAdjusterChrono.

@Test(dataProvider = "calendars")
public void test_badWithAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDate date2 = chrono2.date(refDate);
        TemporalAdjuster adjuster = new FixedAdjuster(date2);
        if (chrono != chrono2) {
            try {
                date.with(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException");
            } catch (ClassCastException cce) {
            // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.with(adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) TemporalAdjuster(java.time.temporal.TemporalAdjuster) 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) ChronoLocalDate(java.time.chrono.ChronoLocalDate) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 49 with Chronology

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

the class TCKChronoLocalDate method test_badPlusAdjusterChrono.

@Test(dataProvider = "calendars")
public void test_badPlusAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDate date2 = chrono2.date(refDate);
        TemporalAmount adjuster = new FixedAdjuster(date2);
        if (chrono != chrono2) {
            try {
                date.plus(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException");
            } catch (ClassCastException cce) {
            // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.plus(adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) TemporalAmount(java.time.temporal.TemporalAmount) 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) ChronoLocalDate(java.time.chrono.ChronoLocalDate) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 50 with Chronology

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

the class TCKChronoLocalDate method test_badPlusTemporalUnitChrono.

@Test(dataProvider = "calendars")
public void test_badPlusTemporalUnitChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDate date2 = chrono2.date(refDate);
        TemporalUnit adjuster = new FixedTemporalUnit(date2);
        if (chrono != chrono2) {
            try {
                date.plus(1, adjuster);
                Assert.fail("TemporalUnit.doAdd plus should have thrown a ClassCastException" + date.getClass() + ", can not be cast to " + date2.getClass());
            } catch (ClassCastException cce) {
            // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.plus(1, adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) TemporalUnit(java.time.temporal.TemporalUnit) 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) ChronoLocalDate(java.time.chrono.ChronoLocalDate) LocalDate(java.time.LocalDate) 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