use of java.time.chrono.Chronology in project j2objc by google.
the class TCKChronoLocalDateTime method test_badMinusAdjusterChrono.
@Test
@UseDataProvider("data_of_calendars")
public void test_badMinusAdjusterChrono(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);
TemporalAmount adjuster = new FixedAdjuster(cdt2);
if (chrono != chrono2) {
try {
cdt.minus(adjuster);
Assert.fail("WithAdjuster should have thrown a ClassCastException, " + "required: " + cdt + ", supplied: " + cdt2);
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoLocalDateTime<?> result = cdt.minus(adjuster);
assertEquals("WithAdjuster failed to replace date", result, cdt2);
}
}
}
use of java.time.chrono.Chronology in project j2objc by google.
the class TCKChronoLocalDateTime method test_datetime_comparisons.
// -----------------------------------------------------------------------
// isBefore, isAfter, isEqual
// -----------------------------------------------------------------------
@Test
@UseDataProvider("data_of_calendars")
public void test_datetime_comparisons(Chronology chrono) {
List<ChronoLocalDateTime<?>> dates = new ArrayList<>();
ChronoLocalDateTime<?> date = chrono.date(LocalDate.of(2013, 1, 1)).atTime(LocalTime.MIN);
// 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<ChronoLocalDateTime<?>> otherDates = new ArrayList<>();
Chronology chrono2 = clist[0];
for (ChronoLocalDateTime<?> d : dates) {
otherDates.add(chrono2.date(d).atTime(d.toLocalTime()));
}
// Now compare the sequence of original dates with the sequence of converted dates
for (int i = 0; i < dates.size(); i++) {
ChronoLocalDateTime<?> a = dates.get(i);
for (int j = 0; j < otherDates.size(); j++) {
ChronoLocalDateTime<?> b = otherDates.get(j);
int cmp = ChronoLocalDateTime.timeLineOrder().compare(a, b);
if (i < j) {
assertTrue(a + " compare " + b, cmp < 0);
assertEquals(a + " isBefore " + b, a.isBefore(b), true);
assertEquals(a + " isAfter " + 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 + " isAfter " + 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 + " isAfter " + b, a.isAfter(b), false);
assertEquals(a + " isEqual " + b, a.isEqual(b), true);
}
}
}
}
}
use of java.time.chrono.Chronology in project j2objc by google.
the class TCKChronoLocalDateTime method test_badWithAdjusterChrono.
@Test
@UseDataProvider("data_of_calendars")
public void test_badWithAdjusterChrono(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);
TemporalAdjuster adjuster = new FixedAdjuster(cdt2);
if (chrono != chrono2) {
try {
cdt.with(adjuster);
Assert.fail("WithAdjuster should have thrown a ClassCastException, " + "required: " + cdt + ", supplied: " + cdt2);
} catch (ClassCastException cce) {
// Expected exception; not an error
}
} else {
// Same chronology,
ChronoLocalDateTime<?> result = cdt.with(adjuster);
assertEquals("WithAdjuster failed to replace date", result, cdt2);
}
}
}
use of java.time.chrono.Chronology in project j2objc by google.
the class TCKChronoZonedDateTime method test_badMinusTemporalUnitChrono.
@Test()
@UseDataProvider("data_of_calendars")
public void test_badMinusTemporalUnitChrono(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);
TemporalUnit adjuster = new FixedTemporalUnit(czdt2);
if (chrono != chrono2) {
try {
czdt.minus(1, adjuster);
Assert.fail("TemporalUnit.doPlus minus 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.minus(1, adjuster);
assertEquals("WithAdjuster failed to replace date", result, czdt2);
}
}
}
use of java.time.chrono.Chronology in project j2objc by google.
the class TCKChronoZonedDateTime method test_badPlusAdjusterChrono.
@Test()
@UseDataProvider("data_of_calendars")
public void test_badPlusAdjusterChrono(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.plus(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.plus(adjuster);
assertEquals("WithAdjuster failed to replace date time", result, czdt2);
}
}
}
Aggregations