use of java.time.temporal.TemporalUnit 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");
}
}
}
use of java.time.temporal.TemporalUnit 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");
}
}
}
use of java.time.temporal.TemporalUnit in project jdk8u_jdk by JetBrains.
the class TCKChronoLocalDateTime method test_badMinusTemporalUnitChrono.
@Test(dataProvider = "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 : 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(result, cdt2, "WithAdjuster failed to replace date");
}
}
}
use of java.time.temporal.TemporalUnit in project jdk8u_jdk by JetBrains.
the class TCKChronoLocalDate method test_badMinusTemporalUnitChrono.
@Test(dataProvider = "calendars")
public void test_badMinusTemporalUnitChrono(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.minus(1, adjuster);
Assert.fail("TemporalUnit.doAdd minus 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.minus(1, adjuster);
assertEquals(result, date2, "WithAdjuster failed to replace date");
}
}
}
use of java.time.temporal.TemporalUnit in project janusgraph by JanusGraph.
the class Durations method parse.
public static TemporalUnit parse(String unitName) {
TemporalUnit unit = unitNames.get(unitName.toLowerCase());
Preconditions.checkArgument(unit != null, "Unknown unit time: %s", unitName);
return unit;
}
Aggregations