Java Code Examples for java.time.Period#ZERO
The following examples show how to use
java.time.Period#ZERO .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AmazonDurationParser.java From ask-sdk-frameworks-java with Apache License 2.0 | 6 votes |
@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); } }
Example 2
Source File: CypherDuration.java From vertexium with Apache License 2.0 | 6 votes |
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); } }
Example 3
Source File: AmazonDurationTest.java From ask-sdk-frameworks-java with Apache License 2.0 | 6 votes |
@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()); }
Example 4
Source File: Parsed.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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; } }
Example 5
Source File: AmazonDurationTest.java From ask-sdk-frameworks-java with Apache License 2.0 | 5 votes |
@Test(expected = IllegalArgumentException.class) public void testNullDuration() { new AmazonDuration( mockSlot, Period.ZERO, null); }
Example 6
Source File: Parsed.java From JDKSourceCode1.8 with MIT License | 5 votes |
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; } }
Example 7
Source File: Parsed.java From Java8CN with Apache License 2.0 | 5 votes |
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; } }
Example 8
Source File: TCKPeriod.java From hottub with GNU General Public License v2.0 | 5 votes |
@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"}, }; }
Example 9
Source File: TestKata3PeriodsAndDurations.java From java-katas with MIT License | 5 votes |
@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"); }
Example 10
Source File: TCKPeriod.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@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"}, }; }
Example 11
Source File: Parsed.java From hottub with GNU General Public License v2.0 | 5 votes |
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; } }
Example 12
Source File: Parsed.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
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; } }
Example 13
Source File: TCKLocalTime.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
@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); }
Example 14
Source File: TCKLocalTime.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@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); }
Example 15
Source File: TCKLocalTime.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
@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); }
Example 16
Source File: TCKLocalTime.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
@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); }
Example 17
Source File: TCKLocalTime.java From hottub with GNU General Public License v2.0 | 4 votes |
@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); }
Example 18
Source File: TCKLocalTime.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@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); }
Example 19
Source File: PersistingDownloadCache.java From flink with Apache License 2.0 | 4 votes |
@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(); }
Example 20
Source File: TCKLocalTime.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@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); }