Java Code Examples for java.time.Period#ofDays()

The following examples show how to use java.time.Period#ofDays() . 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: FHIRPathUtil.java    From FHIR with Apache License 2.0 5 votes vote down vote up
public static TemporalAmount getTemporalAmount(FHIRPathQuantityValue quantityValue) {
    int value = quantityValue.value().intValue();
    String unit = quantityValue.unit();
    switch (unit) {
    case "year":
    case "years":
        return Period.ofYears(value);
    case "month":
    case "months":
        return Period.ofMonths(value);
    case "week":
    case "weeks":
        return Period.ofWeeks(value);
    case "day":
    case "days":
        return Period.ofDays(value);
    case "hour":
    case "hours":
        return Duration.ofHours(value);
    case "minute":
    case "minutes":
        return Duration.ofMinutes(value);
    case "second":
    case "seconds":
        return Duration.ofSeconds(value);
    case "millisecond":
    case "milliseconds":
        return Duration.ofMillis(value);
    default:
        throw new IllegalArgumentException();
    }
}
 
Example 2
Source File: TCKYearMonth.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="plus_TemporalAmount")
Object[][] data_plus_TemporalAmount() {
    return new Object[][] {
        {YearMonth.of(1, 1), Period.ofYears(1), YearMonth.of(2, 1), null},
        {YearMonth.of(1, 1), Period.ofYears(-12), YearMonth.of(-11, 1), null},
        {YearMonth.of(1, 1), Period.ofYears(0), YearMonth.of(1, 1), null},
        {YearMonth.of(999999999, 12), Period.ofYears(0), YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), Period.ofYears(0), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 1), Period.ofYears(-999999999), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 12), Period.ofYears(999999999), YearMonth.of(999999999, 12), null},

        {YearMonth.of(1, 1), Period.ofMonths(1), YearMonth.of(1, 2), null},
        {YearMonth.of(1, 1), Period.ofMonths(-12), YearMonth.of(0, 1), null},
        {YearMonth.of(1, 1), Period.ofMonths(121), YearMonth.of(11, 2), null},
        {YearMonth.of(1, 1), Period.ofMonths(0), YearMonth.of(1, 1), null},
        {YearMonth.of(999999999, 12), Period.ofMonths(0), YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), Period.ofMonths(0), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(-999999999, 2), Period.ofMonths(-1), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(999999999, 11), Period.ofMonths(1), YearMonth.of(999999999, 12), null},

        {YearMonth.of(1, 1), Period.ofYears(1).withMonths(2), YearMonth.of(2, 3), null},
        {YearMonth.of(1, 1), Period.ofYears(-12).withMonths(-1), YearMonth.of(-12, 12), null},

        {YearMonth.of(1, 1), Period.ofMonths(2).withYears(1), YearMonth.of(2, 3), null},
        {YearMonth.of(1, 1), Period.ofMonths(-1).withYears(-12), YearMonth.of(-12, 12), null},

        {YearMonth.of(1, 1), Period.ofDays(365), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofDays(365), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofHours(365*24), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofMinutes(365*24*60), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofSeconds(365*24*3600), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofNanos(365*24*3600*1000000000), null, DateTimeException.class},
    };
}
 
Example 3
Source File: TCKYearMonth.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="minus_TemporalAmount")
Object[][] data_minus_TemporalAmount() {
    return new Object[][] {
        {YearMonth.of(1, 1), Period.ofYears(1), YearMonth.of(0, 1), null},
        {YearMonth.of(1, 1), Period.ofYears(-12), YearMonth.of(13, 1), null},
        {YearMonth.of(1, 1), Period.ofYears(0), YearMonth.of(1, 1), null},
        {YearMonth.of(999999999, 12), Period.ofYears(0), YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), Period.ofYears(0), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 1), Period.ofYears(999999999), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 12), Period.ofYears(-999999999), YearMonth.of(999999999, 12), null},

        {YearMonth.of(1, 1), Period.ofMonths(1), YearMonth.of(0, 12), null},
        {YearMonth.of(1, 1), Period.ofMonths(-12), YearMonth.of(2, 1), null},
        {YearMonth.of(1, 1), Period.ofMonths(121), YearMonth.of(-10, 12), null},
        {YearMonth.of(1, 1), Period.ofMonths(0), YearMonth.of(1, 1), null},
        {YearMonth.of(999999999, 12), Period.ofMonths(0), YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), Period.ofMonths(0), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(-999999999, 2), Period.ofMonths(1), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(999999999, 11), Period.ofMonths(-1), YearMonth.of(999999999, 12), null},

        {YearMonth.of(1, 1), Period.ofYears(1).withMonths(2), YearMonth.of(-1, 11), null},
        {YearMonth.of(1, 1), Period.ofYears(-12).withMonths(-1), YearMonth.of(13, 2), null},

        {YearMonth.of(1, 1), Period.ofMonths(2).withYears(1), YearMonth.of(-1, 11), null},
        {YearMonth.of(1, 1), Period.ofMonths(-1).withYears(-12), YearMonth.of(13, 2), null},

        {YearMonth.of(1, 1), Period.ofDays(365), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofDays(365), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofHours(365*24), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofMinutes(365*24*60), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofSeconds(365*24*3600), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofNanos(365*24*3600*1000000000), null, DateTimeException.class},
    };
}
 
Example 4
Source File: TCKYearMonth.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="minus_TemporalAmount")
Object[][] data_minus_TemporalAmount() {
    return new Object[][] {
        {YearMonth.of(1, 1), Period.ofYears(1), YearMonth.of(0, 1), null},
        {YearMonth.of(1, 1), Period.ofYears(-12), YearMonth.of(13, 1), null},
        {YearMonth.of(1, 1), Period.ofYears(0), YearMonth.of(1, 1), null},
        {YearMonth.of(999999999, 12), Period.ofYears(0), YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), Period.ofYears(0), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 1), Period.ofYears(999999999), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 12), Period.ofYears(-999999999), YearMonth.of(999999999, 12), null},

        {YearMonth.of(1, 1), Period.ofMonths(1), YearMonth.of(0, 12), null},
        {YearMonth.of(1, 1), Period.ofMonths(-12), YearMonth.of(2, 1), null},
        {YearMonth.of(1, 1), Period.ofMonths(121), YearMonth.of(-10, 12), null},
        {YearMonth.of(1, 1), Period.ofMonths(0), YearMonth.of(1, 1), null},
        {YearMonth.of(999999999, 12), Period.ofMonths(0), YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), Period.ofMonths(0), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(-999999999, 2), Period.ofMonths(1), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(999999999, 11), Period.ofMonths(-1), YearMonth.of(999999999, 12), null},

        {YearMonth.of(1, 1), Period.ofYears(1).withMonths(2), YearMonth.of(-1, 11), null},
        {YearMonth.of(1, 1), Period.ofYears(-12).withMonths(-1), YearMonth.of(13, 2), null},

        {YearMonth.of(1, 1), Period.ofMonths(2).withYears(1), YearMonth.of(-1, 11), null},
        {YearMonth.of(1, 1), Period.ofMonths(-1).withYears(-12), YearMonth.of(13, 2), null},

        {YearMonth.of(1, 1), Period.ofDays(365), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofDays(365), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofHours(365*24), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofMinutes(365*24*60), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofSeconds(365*24*3600), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofNanos(365*24*3600*1000000000), null, DateTimeException.class},
    };
}
 
Example 5
Source File: TestPeriod.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_hashCode() {
    Period test5 = Period.ofDays(5);
    Period test6 = Period.ofDays(6);
    Period test5M = Period.ofMonths(5);
    Period test5Y = Period.ofYears(5);
    assertEquals(test5.hashCode() == test5.hashCode(), true);
    assertEquals(test5.hashCode() == test6.hashCode(), false);
    assertEquals(test5.hashCode() == test5M.hashCode(), false);
    assertEquals(test5.hashCode() == test5Y.hashCode(), false);
}
 
Example 6
Source File: TestPeriod.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_hashCode() {
    Period test5 = Period.ofDays(5);
    Period test6 = Period.ofDays(6);
    Period test5M = Period.ofMonths(5);
    Period test5Y = Period.ofYears(5);
    assertEquals(test5.hashCode() == test5.hashCode(), true);
    assertEquals(test5.hashCode() == test6.hashCode(), false);
    assertEquals(test5.hashCode() == test5M.hashCode(), false);
    assertEquals(test5.hashCode() == test5Y.hashCode(), false);
}
 
Example 7
Source File: RangeFilterTests.java    From morpheus-core with Apache License 2.0 5 votes vote down vote up
@DataProvider(name="LocalDateRanges")
public Object[][] localDateRanges() {
    return new Object[][] {
            { LocalDate.of(1990, 1, 1), LocalDate.of(1990, 12, 31), Period.ofDays(1), false },
            { LocalDate.of(1990, 1, 1), LocalDate.of(1990, 12, 31), Period.ofDays(5), false },
            { LocalDate.of(2014, 12, 1), LocalDate.of(2013, 1, 1), Period.ofDays(3), false },
            { LocalDate.of(2014, 12, 1), LocalDate.of(2014, 1, 1), Period.ofDays(6), false },
            { LocalDate.of(1990, 1, 1), LocalDate.of(1990, 12, 31), Period.ofDays(1), true },
            { LocalDate.of(1990, 1, 1), LocalDate.of(1990, 12, 31), Period.ofDays(5), true },
            { LocalDate.of(2014, 12, 1), LocalDate.of(2013, 1, 1), Period.ofDays(3), true },
            { LocalDate.of(2014, 12, 1), LocalDate.of(2014, 1, 1), Period.ofDays(6), true },
    };
}
 
Example 8
Source File: PsqlReplicationCheckTest.java    From dbeam with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldBeReplicationDelayedWhenReplicatedBeforePartitionStart() {
  Instant partition = Instant.parse("2027-07-31T00:00:00Z");
  Instant lastReplication = Instant.parse("2027-07-30T22:00:00Z");
  Period partitionPeriod = Period.ofDays(1);

  Assert.assertTrue(
      PsqlReplicationCheck.isReplicationDelayed(partition, lastReplication, partitionPeriod));
}
 
Example 9
Source File: TCKYearMonth.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="plus_TemporalAmount")
Object[][] data_plus_TemporalAmount() {
    return new Object[][] {
        {YearMonth.of(1, 1), Period.ofYears(1), YearMonth.of(2, 1), null},
        {YearMonth.of(1, 1), Period.ofYears(-12), YearMonth.of(-11, 1), null},
        {YearMonth.of(1, 1), Period.ofYears(0), YearMonth.of(1, 1), null},
        {YearMonth.of(999999999, 12), Period.ofYears(0), YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), Period.ofYears(0), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 1), Period.ofYears(-999999999), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 12), Period.ofYears(999999999), YearMonth.of(999999999, 12), null},

        {YearMonth.of(1, 1), Period.ofMonths(1), YearMonth.of(1, 2), null},
        {YearMonth.of(1, 1), Period.ofMonths(-12), YearMonth.of(0, 1), null},
        {YearMonth.of(1, 1), Period.ofMonths(121), YearMonth.of(11, 2), null},
        {YearMonth.of(1, 1), Period.ofMonths(0), YearMonth.of(1, 1), null},
        {YearMonth.of(999999999, 12), Period.ofMonths(0), YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), Period.ofMonths(0), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(-999999999, 2), Period.ofMonths(-1), YearMonth.of(-999999999, 1), null},
        {YearMonth.of(999999999, 11), Period.ofMonths(1), YearMonth.of(999999999, 12), null},

        {YearMonth.of(1, 1), Period.ofYears(1).withMonths(2), YearMonth.of(2, 3), null},
        {YearMonth.of(1, 1), Period.ofYears(-12).withMonths(-1), YearMonth.of(-12, 12), null},

        {YearMonth.of(1, 1), Period.ofMonths(2).withYears(1), YearMonth.of(2, 3), null},
        {YearMonth.of(1, 1), Period.ofMonths(-1).withYears(-12), YearMonth.of(-12, 12), null},

        {YearMonth.of(1, 1), Period.ofDays(365), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofDays(365), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofHours(365*24), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofMinutes(365*24*60), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofSeconds(365*24*3600), null, DateTimeException.class},
        {YearMonth.of(1, 1), Duration.ofNanos(365*24*3600*1000000000), null, DateTimeException.class},
    };
}
 
Example 10
Source File: TCKPeriod.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void test_minusDays_overflowTooBig() {
    Period test = Period.ofDays(Integer.MAX_VALUE);
    test.minusDays(-1);
}
 
Example 11
Source File: TCKPeriod.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@DataProvider(name="parseSuccess")
Object[][] data_factory_parseSuccess() {
    return new Object[][] {
            {"P1Y", Period.ofYears(1)},
            {"P12Y", Period.ofYears(12)},
            {"P987654321Y", Period.ofYears(987654321)},
            {"P+1Y", Period.ofYears(1)},
            {"P+12Y", Period.ofYears(12)},
            {"P+987654321Y", Period.ofYears(987654321)},
            {"P+0Y", Period.ofYears(0)},
            {"P0Y", Period.ofYears(0)},
            {"P-0Y", Period.ofYears(0)},
            {"P-25Y", Period.ofYears(-25)},
            {"P-987654321Y", Period.ofYears(-987654321)},
            {"P" + Integer.MAX_VALUE + "Y", Period.ofYears(Integer.MAX_VALUE)},
            {"P" + Integer.MIN_VALUE + "Y", Period.ofYears(Integer.MIN_VALUE)},

            {"P1M", Period.ofMonths(1)},
            {"P12M", Period.ofMonths(12)},
            {"P987654321M", Period.ofMonths(987654321)},
            {"P+1M", Period.ofMonths(1)},
            {"P+12M", Period.ofMonths(12)},
            {"P+987654321M", Period.ofMonths(987654321)},
            {"P+0M", Period.ofMonths(0)},
            {"P0M", Period.ofMonths(0)},
            {"P-0M", Period.ofMonths(0)},
            {"P-25M", Period.ofMonths(-25)},
            {"P-987654321M", Period.ofMonths(-987654321)},
            {"P" + Integer.MAX_VALUE + "M", Period.ofMonths(Integer.MAX_VALUE)},
            {"P" + Integer.MIN_VALUE + "M", Period.ofMonths(Integer.MIN_VALUE)},

            {"P1W", Period.ofDays(1 * 7)},
            {"P12W", Period.ofDays(12 * 7)},
            {"P7654321W", Period.ofDays(7654321 * 7)},
            {"P+1W", Period.ofDays(1 * 7)},
            {"P+12W", Period.ofDays(12 * 7)},
            {"P+7654321W", Period.ofDays(7654321 * 7)},
            {"P+0W", Period.ofDays(0)},
            {"P0W", Period.ofDays(0)},
            {"P-0W", Period.ofDays(0)},
            {"P-25W", Period.ofDays(-25 * 7)},
            {"P-7654321W", Period.ofDays(-7654321 * 7)},

            {"P1D", Period.ofDays(1)},
            {"P12D", Period.ofDays(12)},
            {"P987654321D", Period.ofDays(987654321)},
            {"P+1D", Period.ofDays(1)},
            {"P+12D", Period.ofDays(12)},
            {"P+987654321D", Period.ofDays(987654321)},
            {"P+0D", Period.ofDays(0)},
            {"P0D", Period.ofDays(0)},
            {"P-0D", Period.ofDays(0)},
            {"P-25D", Period.ofDays(-25)},
            {"P-987654321D", Period.ofDays(-987654321)},
            {"P" + Integer.MAX_VALUE + "D", Period.ofDays(Integer.MAX_VALUE)},
            {"P" + Integer.MIN_VALUE + "D", Period.ofDays(Integer.MIN_VALUE)},

            {"P0Y0M0D", Period.of(0, 0, 0)},
            {"P2Y0M0D", Period.of(2, 0, 0)},
            {"P0Y3M0D", Period.of(0, 3, 0)},
            {"P0Y0M4D", Period.of(0, 0, 4)},
            {"P2Y3M25D", Period.of(2, 3, 25)},
            {"P-2Y3M25D", Period.of(-2, 3, 25)},
            {"P2Y-3M25D", Period.of(2, -3, 25)},
            {"P2Y3M-25D", Period.of(2, 3, -25)},
            {"P-2Y-3M-25D", Period.of(-2, -3, -25)},

            {"P0Y0M0W0D", Period.of(0, 0, 0)},
            {"P2Y3M4W25D", Period.of(2, 3, 4 * 7 + 25)},
            {"P-2Y-3M-4W-25D", Period.of(-2, -3, -4 * 7 - 25)},
    };
}
 
Example 12
Source File: TCKPeriod.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void test_plusDays_overflowTooBig() {
    Period test = Period.ofDays(Integer.MAX_VALUE);
    test.plusDays(1);
}
 
Example 13
Source File: TCKPeriod.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void test_minusDays_overflowTooSmall() {
    Period test = Period.ofDays(Integer.MIN_VALUE);
    test.minusDays(1);
}
 
Example 14
Source File: TCKPeriod.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void test_minusDays_overflowTooBig() {
    Period test = Period.ofDays(Integer.MAX_VALUE);
    test.minusDays(-1);
}
 
Example 15
Source File: TCKPeriod.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void test_minusDays_overflowTooBig() {
    Period test = Period.ofDays(Integer.MAX_VALUE);
    test.minusDays(-1);
}
 
Example 16
Source File: TCKPeriod.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void test_plusDays_overflowTooSmall() {
    Period test = Period.ofDays(Integer.MIN_VALUE);
    test.plusDays(-1);
}
 
Example 17
Source File: TCKPeriod.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@DataProvider
public static Object[][] data_factory_parseSuccess() {
    return new Object[][] {
            {"P1Y", Period.ofYears(1)},
            {"P12Y", Period.ofYears(12)},
            {"P987654321Y", Period.ofYears(987654321)},
            {"P+1Y", Period.ofYears(1)},
            {"P+12Y", Period.ofYears(12)},
            {"P+987654321Y", Period.ofYears(987654321)},
            {"P+0Y", Period.ofYears(0)},
            {"P0Y", Period.ofYears(0)},
            {"P-0Y", Period.ofYears(0)},
            {"P-25Y", Period.ofYears(-25)},
            {"P-987654321Y", Period.ofYears(-987654321)},
            {"P" + Integer.MAX_VALUE + "Y", Period.ofYears(Integer.MAX_VALUE)},
            {"P" + Integer.MIN_VALUE + "Y", Period.ofYears(Integer.MIN_VALUE)},

            {"P1M", Period.ofMonths(1)},
            {"P12M", Period.ofMonths(12)},
            {"P987654321M", Period.ofMonths(987654321)},
            {"P+1M", Period.ofMonths(1)},
            {"P+12M", Period.ofMonths(12)},
            {"P+987654321M", Period.ofMonths(987654321)},
            {"P+0M", Period.ofMonths(0)},
            {"P0M", Period.ofMonths(0)},
            {"P-0M", Period.ofMonths(0)},
            {"P-25M", Period.ofMonths(-25)},
            {"P-987654321M", Period.ofMonths(-987654321)},
            {"P" + Integer.MAX_VALUE + "M", Period.ofMonths(Integer.MAX_VALUE)},
            {"P" + Integer.MIN_VALUE + "M", Period.ofMonths(Integer.MIN_VALUE)},

            {"P1W", Period.ofDays(1 * 7)},
            {"P12W", Period.ofDays(12 * 7)},
            {"P7654321W", Period.ofDays(7654321 * 7)},
            {"P+1W", Period.ofDays(1 * 7)},
            {"P+12W", Period.ofDays(12 * 7)},
            {"P+7654321W", Period.ofDays(7654321 * 7)},
            {"P+0W", Period.ofDays(0)},
            {"P0W", Period.ofDays(0)},
            {"P-0W", Period.ofDays(0)},
            {"P-25W", Period.ofDays(-25 * 7)},
            {"P-7654321W", Period.ofDays(-7654321 * 7)},

            {"P1D", Period.ofDays(1)},
            {"P12D", Period.ofDays(12)},
            {"P987654321D", Period.ofDays(987654321)},
            {"P+1D", Period.ofDays(1)},
            {"P+12D", Period.ofDays(12)},
            {"P+987654321D", Period.ofDays(987654321)},
            {"P+0D", Period.ofDays(0)},
            {"P0D", Period.ofDays(0)},
            {"P-0D", Period.ofDays(0)},
            {"P-25D", Period.ofDays(-25)},
            {"P-987654321D", Period.ofDays(-987654321)},
            {"P" + Integer.MAX_VALUE + "D", Period.ofDays(Integer.MAX_VALUE)},
            {"P" + Integer.MIN_VALUE + "D", Period.ofDays(Integer.MIN_VALUE)},

            {"P0Y0M0D", Period.of(0, 0, 0)},
            {"P2Y0M0D", Period.of(2, 0, 0)},
            {"P0Y3M0D", Period.of(0, 3, 0)},
            {"P0Y0M4D", Period.of(0, 0, 4)},
            {"P2Y3M25D", Period.of(2, 3, 25)},
            {"P-2Y3M25D", Period.of(-2, 3, 25)},
            {"P2Y-3M25D", Period.of(2, -3, 25)},
            {"P2Y3M-25D", Period.of(2, 3, -25)},
            {"P-2Y-3M-25D", Period.of(-2, -3, -25)},

            {"P0Y0M0W0D", Period.of(0, 0, 0)},
            {"P2Y3M4W25D", Period.of(2, 3, 4 * 7 + 25)},
            {"P-2Y-3M-4W-25D", Period.of(-2, -3, -4 * 7 - 25)},
    };
}
 
Example 18
Source File: TCKPeriod.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void test_minusDays_overflowTooBig() {
    Period test = Period.ofDays(Integer.MAX_VALUE);
    test.minusDays(-1);
}
 
Example 19
Source File: TCKPeriod.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void test_plusDays_overflowTooBig() {
    Period test = Period.ofDays(Integer.MAX_VALUE);
    test.plusDays(1);
}
 
Example 20
Source File: TCKPeriod.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void test_plusDays_overflowTooBig() {
    Period test = Period.ofDays(Integer.MAX_VALUE);
    test.plusDays(1);
}