Search in sources :

Example 41 with Chronology

use of java.time.chrono.Chronology in project j2objc by google.

the class TCKChronoZonedDateTime method test_badTemporalFieldChrono.

@Test()
@UseDataProvider("data_of_calendars")
public void test_badTemporalFieldChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
    for (Chronology[] clist : (Chronology[][]) data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
        TemporalField adjuster = new FixedTemporalField(czdt2);
        if (chrono != chrono2) {
            try {
                czdt.with(adjuster, 1);
                Assert.fail("TemporalField doWith() should have thrown a ClassCastException, " + czdt.getClass() + " can not be cast to " + czdt2.getClass());
            } catch (ClassCastException cce) {
            // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoZonedDateTime<?> result = czdt.with(adjuster, 1);
            assertEquals("TemporalField doWith() failed to replace date", result, czdt2);
        }
    }
}
Also used : TemporalField(java.time.temporal.TemporalField) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) LocalDate(java.time.LocalDate) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 42 with Chronology

use of java.time.chrono.Chronology in project j2objc by google.

the class TCKChronoZonedDateTime method test_badMinusAdjusterChrono.

@Test()
@UseDataProvider("data_of_calendars")
public void test_badMinusAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
    for (Chronology[] clist : (Chronology[][]) data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
        TemporalAmount adjuster = new FixedAdjuster(czdt2);
        if (chrono != chrono2) {
            try {
                czdt.minus(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException, " + "required: " + czdt + ", supplied: " + czdt2);
            } catch (ClassCastException cce) {
            // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoZonedDateTime<?> result = czdt.minus(adjuster);
            assertEquals("WithAdjuster failed to replace date", result, czdt2);
        }
    }
}
Also used : TemporalAmount(java.time.temporal.TemporalAmount) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) LocalDate(java.time.LocalDate) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 43 with Chronology

use of java.time.chrono.Chronology in project j2objc by google.

the class TCKChronoZonedDateTime method test_zonedDateTime_comparisons.

// -----------------------------------------------------------------------
// isBefore, isAfter, isEqual, timeLineOrder()  test a Chronology against the other Chronos
// -----------------------------------------------------------------------
@Test()
@UseDataProvider("data_of_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 : (Chronology[][]) 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(a + " compare " + b, cmp < 0);
                    assertEquals(a + " isBefore " + b, a.isBefore(b), true);
                    assertEquals(a + " ifAfter " + b, a.isAfter(b), false);
                    assertEquals(a + " isEqual " + b, a.isEqual(b), false);
                } else if (i > j) {
                    assertTrue(a + " compare " + b, cmp > 0);
                    assertEquals(a + " isBefore " + b, a.isBefore(b), false);
                    assertEquals(a + " ifAfter " + b, a.isAfter(b), true);
                    assertEquals(a + " isEqual " + b, a.isEqual(b), false);
                } else {
                    assertTrue(a + " compare " + b, cmp == 0);
                    assertEquals(a + " isBefore " + b, a.isBefore(b), false);
                    assertEquals(a + " ifAfter " + b, a.isAfter(b), false);
                    assertEquals(a + " isEqual " + b, a.isEqual(b), true);
                }
            }
        }
    }
}
Also used : ChronoZonedDateTime(java.time.chrono.ChronoZonedDateTime) ArrayList(java.util.ArrayList) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 44 with Chronology

use of java.time.chrono.Chronology in project j2objc by google.

the class TCKChronoLocalDateTime method test_badMinusTemporalUnitChrono.

@Test
@UseDataProvider("data_of_calendars")
public void test_badMinusTemporalUnitChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
    for (Chronology[] clist : (Chronology[][]) data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
        TemporalUnit adjuster = new FixedTemporalUnit(cdt2);
        if (chrono != chrono2) {
            try {
                cdt.minus(1, adjuster);
                Assert.fail("TemporalUnit.doPlus minus 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.minus(1, adjuster);
            assertEquals("WithAdjuster failed to replace date", result, cdt2);
        }
    }
}
Also used : TemporalUnit(java.time.temporal.TemporalUnit) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) LocalDate(java.time.LocalDate) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 45 with Chronology

use of java.time.chrono.Chronology in project j2objc by google.

the class TCKChronoLocalDateTime method test_badPlusTemporalUnitChrono.

@Test
@UseDataProvider("data_of_calendars")
public void test_badPlusTemporalUnitChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
    for (Chronology[] clist : (Chronology[][]) data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
        TemporalUnit adjuster = new FixedTemporalUnit(cdt2);
        if (chrono != chrono2) {
            try {
                cdt.plus(1, adjuster);
                Assert.fail("TemporalUnit.doPlus plus should have thrown a ClassCastException" + cdt + ", can not be cast to " + cdt2);
            } catch (ClassCastException cce) {
            // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDateTime<?> result = cdt.plus(1, adjuster);
            assertEquals("WithAdjuster failed to replace date", result, cdt2);
        }
    }
}
Also used : TemporalUnit(java.time.temporal.TemporalUnit) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) LocalDate(java.time.LocalDate) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

Chronology (java.time.chrono.Chronology)114 IsoChronology (java.time.chrono.IsoChronology)95 Test (org.testng.annotations.Test)66 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)42 LocalDate (java.time.LocalDate)39 Test (org.junit.Test)32 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)27 TemporalAmount (java.time.temporal.TemporalAmount)12 TemporalUnit (java.time.temporal.TemporalUnit)12 TemporalAccessor (java.time.temporal.TemporalAccessor)10 TemporalField (java.time.temporal.TemporalField)9 ZoneId (java.time.ZoneId)8 Locale (java.util.Locale)8 DateTimeException (java.time.DateTimeException)6 TemporalAdjuster (java.time.temporal.TemporalAdjuster)6 ArrayList (java.util.ArrayList)6