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

The following examples show how to use java.time.Period#ofMonths() . 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: TenorTest.java    From Strata with Apache License 2.0 5 votes vote down vote up
public static Object[][] data_ofMonths() {
  return new Object[][] {
      {1, Period.ofMonths(1), "1M"},
      {2, Period.ofMonths(2), "2M"},
      {12, Period.ofMonths(12), "12M"},
      {20, Period.ofMonths(20), "20M"},
      {24, Period.ofMonths(24), "24M"},
      {30, Period.ofMonths(30), "30M"},
  };
}
 
Example 2
Source File: TCKPeriod.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
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-jdk9 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 5
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 6
Source File: TCKPeriod.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 7
Source File: TCKPeriod.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@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 8
Source File: TestPeriod.java    From jdk8u60 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 9
Source File: TCKPeriod.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 10
Source File: TCKPeriod.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@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: TestPeriod.java    From dragonwell8_jdk 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 12
Source File: TCKYearMonth.java    From TencentKona-8 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 13
Source File: TCKPeriod.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@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 14
Source File: TCKPeriod.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void test_plusMonths_overflowTooBig() {
    Period test = Period.ofMonths(Integer.MAX_VALUE);
    test.plusMonths(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_plusMonths_overflowTooBig() {
    Period test = Period.ofMonths(Integer.MAX_VALUE);
    test.plusMonths(1);
}
 
Example 16
Source File: TCKPeriod.java    From TencentKona-8 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 17
Source File: TCKPeriod.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void test_minusMonths_overflowTooBig() {
    Period test = Period.ofMonths(Integer.MAX_VALUE);
    test.minusMonths(-1);
}
 
Example 18
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_plusMonths_overflowTooBig() {
    Period test = Period.ofMonths(Integer.MAX_VALUE);
    test.plusMonths(1);
}
 
Example 19
Source File: TCKPeriod.java    From openjdk-jdk9 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 20
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)},
    };
}