java.time.Period#ofYears ( )源码实例Demo

下面列出了java.time.Period#ofYears ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FHIR   文件: FHIRPathUtil.java
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();
    }
}
 
源代码2 项目: dragonwell8_jdk   文件: TCKYearMonth.java
@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},
    };
}
 
源代码3 项目: openjdk-jdk8u-backup   文件: TCKPeriod.java
@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"},
    };
}
 
源代码4 项目: jdk8u-jdk   文件: TCKYear.java
@DataProvider(name="plusValid")
Object[][] data_plusValid() {
    return new Object[][] {
            {2012, Period.ofYears(0), 2012},
            {2012, Period.ofYears(1), 2013},
            {2012, Period.ofYears(2), 2014},
            {2012, Period.ofYears(-2), 2010},
    };
}
 
源代码5 项目: jdk8u60   文件: TCKYear.java
@DataProvider(name="minusValid")
Object[][] data_minusValid() {
    return new Object[][] {
            {2012, Period.ofYears(0), 2012},
            {2012, Period.ofYears(1), 2011},
            {2012, Period.ofYears(2), 2010},
            {2012, Period.ofYears(-2), 2014},
    };
}
 
源代码6 项目: openjdk-8   文件: TCKPeriod.java
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);
}
 
源代码7 项目: openjdk-8-source   文件: TCKYearMonth.java
@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},
    };
}
 
源代码8 项目: dragonwell8_jdk   文件: TCKPeriod.java
@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"},
    };
}
 
源代码9 项目: jdk8u_jdk   文件: TCKYearMonth.java
@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},
    };
}
 
源代码10 项目: TencentKona-8   文件: TCKYearMonth.java
@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},
    };
}
 
源代码11 项目: openjdk-jdk9   文件: TCKYear.java
@DataProvider(name="minusValid")
Object[][] data_minusValid() {
    return new Object[][] {
            {2012, Period.ofYears(0), 2012},
            {2012, Period.ofYears(1), 2011},
            {2012, Period.ofYears(2), 2010},
            {2012, Period.ofYears(-2), 2014},
    };
}
 
源代码12 项目: openjdk-jdk9   文件: TCKPeriod.java
@Test(expectedExceptions=ArithmeticException.class)
public void test_multipliedBy_overflowTooBig() {
    Period test = Period.ofYears(Integer.MAX_VALUE / 2 + 1);
    test.multipliedBy(2);
}
 
源代码13 项目: jdk8u60   文件: TCKPeriod.java
@Test(expectedExceptions=ArithmeticException.class)
public void test_multipliedBy_overflowTooSmall() {
    Period test = Period.ofYears(Integer.MIN_VALUE / 2 - 1);
    test.multipliedBy(2);
}
 
源代码14 项目: jdk8u-jdk   文件: TCKPeriod.java
@Test(expectedExceptions=ArithmeticException.class)
public void test_plusYears_overflowTooSmall() {
    Period test = Period.ofYears(Integer.MIN_VALUE);
    test.plusYears(-1);
}
 
源代码15 项目: openjdk-8   文件: TCKPeriod.java
@Test(expectedExceptions=ArithmeticException.class)
public void test_minusYears_overflowTooSmall() {
    Period test = Period.ofYears(Integer.MIN_VALUE);
    test.minusYears(1);
}
 
源代码16 项目: TencentKona-8   文件: TCKPeriod.java
@Test(expectedExceptions=ArithmeticException.class)
public void test_plusYears_overflowTooBig() {
    Period test = Period.ofYears(Integer.MAX_VALUE);
    test.plusYears(1);
}
 
源代码17 项目: jdk8u-jdk   文件: TCKPeriod.java
@Test(expectedExceptions=ArithmeticException.class)
public void test_minusYears_overflowTooSmall() {
    Period test = Period.ofYears(Integer.MIN_VALUE);
    test.minusYears(1);
}
 
源代码18 项目: jdk8u-jdk   文件: TCKPeriod.java
@Test(expectedExceptions=ArithmeticException.class)
public void test_plusYears_overflowTooBig() {
    Period test = Period.ofYears(Integer.MAX_VALUE);
    test.plusYears(1);
}
 
源代码19 项目: hottub   文件: TCKPeriod.java
@Test(expectedExceptions=ArithmeticException.class)
public void test_minusYears_overflowTooSmall() {
    Period test = Period.ofYears(Integer.MIN_VALUE);
    test.minusYears(1);
}
 
源代码20 项目: openjdk-8   文件: TCKPeriod.java
@Test(expectedExceptions=ArithmeticException.class)
public void test_plusYears_overflowTooSmall() {
    Period test = Period.ofYears(Integer.MIN_VALUE);
    test.plusYears(-1);
}