下面列出了java.time.Period#ZERO 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public CypherDuration truncatedTo(ChronoUnit units) {
Period period = this.period;
Duration duration = Duration.ofNanos(nanos);
if (negative) {
period = period.negated();
duration = duration.negated();
}
switch (units) {
case SECONDS:
return new CypherDuration(Period.ZERO, duration);
case DAYS:
return new CypherDuration(period, Duration.ZERO);
case MONTHS:
return new CypherDuration(period.withDays(0), Duration.ZERO);
default:
throw new VertexiumCypherNotImplemented("Unimplemented truncate to: " + units);
}
}
@Test
public void testNotEqualsDifferentPeriod() {
AmazonDuration left = new AmazonDuration(
mockSlot,
Period.ZERO,
Duration.ZERO);
AmazonDuration right = new AmazonDuration(
mockSlot,
Period.ofDays(1),
Duration.ZERO);
assertNotEquals(left, right);
assertNotEquals(left.getPeriod(), right.getPeriod());
assertEquals(left.getDuration(), right.getDuration());
assertEquals(left.getSlot(), right.getSlot());
assertNotEquals(left.hashCode(), right.hashCode());
assertNotEquals(left.toString(), right.toString());
}
@Override
public AmazonDuration read(IntentRequest intentRequest, Slot slot) throws SlotValueParseException {
String value = slot.getValue();
String[] split = SPLIT_PATTERN.split(value, 2);
try {
if (split.length == 1) {
return new AmazonDuration(slot, Period.parse(value), Duration.ZERO);
} else {
Period p;
if (split[0].equals("P")) p = Period.ZERO;
else p = Period.parse(split[0]);
return new AmazonDuration(slot, p, Duration.parse("PT" + split[1]));
}
} catch (DateTimeParseException ex) {
throw new SlotValueParseException(slot, AmazonDuration.class, ex);
}
}
private void resolvePeriod() {
// add whole days if we have both date and time
if (date != null && time != null && excessDays.isZero() == false) {
date = date.plus(excessDays);
excessDays = Period.ZERO;
}
}
private void resolvePeriod() {
// add whole days if we have both date and time
if (date != null && time != null && excessDays.isZero() == false) {
date = date.plus(excessDays);
excessDays = Period.ZERO;
}
}
private void resolvePeriod() {
// add whole days if we have both date and time
if (date != null && time != null && excessDays.isZero() == false) {
date = date.plus(excessDays);
excessDays = Period.ZERO;
}
}
@DataProvider(name="toStringAndParse")
Object[][] data_toString() {
return new Object[][] {
{Period.ZERO, "P0D"},
{Period.ofDays(0), "P0D"},
{Period.ofYears(1), "P1Y"},
{Period.ofMonths(1), "P1M"},
{Period.ofDays(1), "P1D"},
{Period.of(1, 2, 0), "P1Y2M"},
{Period.of(0, 2, 3), "P2M3D"},
{Period.of(1, 2, 3), "P1Y2M3D"},
};
}
@Test
@Tag("TODO")
@Order(2)
public void verifyPeriodCreatedUsingFluentMethods() {
// Create a Period instance
// TODO: Replace the Period.ZERO to a time period of 20 years and 10 days.
// Check : java.time.Period.ofYears(int).withDays(int)
Period twentyYearsAndTenDays = Period.ZERO;
assertEquals(20,
twentyYearsAndTenDays.get(ChronoUnit.YEARS),
"The Period should include twenty years");
assertEquals(10,
twentyYearsAndTenDays.get(ChronoUnit.DAYS),
"The Period should include ten days");
// Add the Period to a LocalDateTime
LocalDateTime tOJDateTime = LocalDateTime.now(terminatorOriginalJudgementDay);
// TODO: Call a method on tOJDateTime to add the newly created Period
// Check : java.time.LocalDateTime.plus(java.time.temporal.TemporalAmount)
LocalDateTime calculatedTwentyYearsAndTenDaysLater =
tOJDateTime;
//1997-08-29 after 20 years and 10 days => 2017-09=08
assertEquals(2017,
calculatedTwentyYearsAndTenDaysLater.getYear(),
"The year after 20 years and 10 days should be 2017");
assertEquals(9,
calculatedTwentyYearsAndTenDaysLater.getMonthValue(),
"The month value after 20 years and 10 days should be 9");
assertEquals(8,
calculatedTwentyYearsAndTenDaysLater.getDayOfMonth(),
"The date after 20 years and 10 days should be 8");
}
@DataProvider(name="toStringAndParse")
Object[][] data_toString() {
return new Object[][] {
{Period.ZERO, "P0D"},
{Period.ofDays(0), "P0D"},
{Period.ofYears(1), "P1Y"},
{Period.ofMonths(1), "P1M"},
{Period.ofDays(1), "P1D"},
{Period.of(1, 2, 0), "P1Y2M"},
{Period.of(0, 2, 3), "P2M3D"},
{Period.of(1, 2, 3), "P1Y2M3D"},
};
}
private void resolvePeriod() {
// add whole days if we have both date and time
if (date != null && time != null && excessDays.isZero() == false) {
date = date.plus(excessDays);
excessDays = Period.ZERO;
}
}
private void resolvePeriod() {
// add whole days if we have both date and time
if (date != null && time != null && excessDays.isZero() == false) {
date = date.plus(excessDays);
excessDays = Period.ZERO;
}
}
@Test(expected = IllegalArgumentException.class)
public void testNullDuration() {
new AmazonDuration(
mockSlot,
Period.ZERO,
null);
}
@Test
public void test_plus_TemporalAmount_zero() {
TemporalAmount period = Period.ZERO;
LocalTime t = TEST_12_30_40_987654321.plus(period);
assertEquals(t, TEST_12_30_40_987654321);
}
@Test
public void test_minus_TemporalAmount_zero() {
TemporalAmount period = Period.ZERO;
LocalTime t = TEST_12_30_40_987654321.minus(period);
assertEquals(t, TEST_12_30_40_987654321);
}
@Test
public void test_plus_TemporalAmount_zero() {
TemporalAmount period = Period.ZERO;
LocalTime t = TEST_12_30_40_987654321.plus(period);
assertEquals(t, TEST_12_30_40_987654321);
}
@Test
public void test_plus_TemporalAmount_zero() {
TemporalAmount period = Period.ZERO;
LocalTime t = TEST_12_30_40_987654321.plus(period);
assertEquals(t, TEST_12_30_40_987654321);
}
@Test
public void test_plus_TemporalAmount_zero() {
TemporalAmount period = Period.ZERO;
LocalTime t = TEST_12_30_40_987654321.plus(period);
assertEquals(t, TEST_12_30_40_987654321);
}
@Test
public void test_minus_TemporalAmount_zero() {
TemporalAmount period = Period.ZERO;
LocalTime t = TEST_12_30_40_987654321.minus(period);
assertEquals(t, TEST_12_30_40_987654321);
}
@Override
boolean exceedsTimeToLive(final Matcher matcher) {
final LocalDate cacheFileDate = LocalDate.parse(matcher.group("date"), DATE_FORMATTER);
return ttl != Period.ZERO && Period.between(cacheFileDate, LocalDate.now()).getDays() > ttl.getDays();
}
@Test
public void test_minus_TemporalAmount_zero() {
TemporalAmount period = Period.ZERO;
LocalTime t = TEST_12_30_40_987654321.minus(period);
assertEquals(t, TEST_12_30_40_987654321);
}