类java.time.Year源码实例Demo

下面列出了怎么用java.time.Year的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: jdk8u_jdk   文件: TCKYear.java
@DataProvider(name="plus_long_TemporalUnit")
Object[][] data_plus_long_TemporalUnit() {
    return new Object[][] {
        {Year.of(1), 1, ChronoUnit.YEARS, Year.of(2), null},
        {Year.of(1), -12, ChronoUnit.YEARS, Year.of(-11), null},
        {Year.of(1), 0, ChronoUnit.YEARS, Year.of(1), null},
        {Year.of(999999999), 0, ChronoUnit.YEARS, Year.of(999999999), null},
        {Year.of(-999999999), 0, ChronoUnit.YEARS, Year.of(-999999999), null},
        {Year.of(0), -999999999, ChronoUnit.YEARS, Year.of(-999999999), null},
        {Year.of(0), 999999999, ChronoUnit.YEARS, Year.of(999999999), null},

        {Year.of(-1), 1, ChronoUnit.ERAS, Year.of(2), null},
        {Year.of(5), 1, ChronoUnit.CENTURIES, Year.of(105), null},
        {Year.of(5), 1, ChronoUnit.DECADES, Year.of(15), null},

        {Year.of(999999999), 1, ChronoUnit.YEARS, null, DateTimeException.class},
        {Year.of(-999999999), -1, ChronoUnit.YEARS, null, DateTimeException.class},

        {Year.of(1), 0, ChronoUnit.DAYS, null, DateTimeException.class},
        {Year.of(1), 0, ChronoUnit.WEEKS, null, DateTimeException.class},
        {Year.of(1), 0, ChronoUnit.MONTHS, null, DateTimeException.class},
    };
}
 
源代码2 项目: jdk8u-jdk   文件: TCKYear.java
@DataProvider(name="minus_long_TemporalUnit")
Object[][] data_minus_long_TemporalUnit() {
    return new Object[][] {
        {Year.of(1), 1, ChronoUnit.YEARS, Year.of(0), null},
        {Year.of(1), -12, ChronoUnit.YEARS, Year.of(13), null},
        {Year.of(1), 0, ChronoUnit.YEARS, Year.of(1), null},
        {Year.of(999999999), 0, ChronoUnit.YEARS, Year.of(999999999), null},
        {Year.of(-999999999), 0, ChronoUnit.YEARS, Year.of(-999999999), null},
        {Year.of(0), -999999999, ChronoUnit.YEARS, Year.of(999999999), null},
        {Year.of(0), 999999999, ChronoUnit.YEARS, Year.of(-999999999), null},

        {Year.of(999999999), 1, ChronoUnit.ERAS, Year.of(-999999999 + 1), null},
        {Year.of(105), 1, ChronoUnit.CENTURIES, Year.of(5), null},
        {Year.of(15), 1, ChronoUnit.DECADES, Year.of(5), null},

        {Year.of(-999999999), 1, ChronoUnit.YEARS, null, DateTimeException.class},
        {Year.of(1), -999999999, ChronoUnit.YEARS, null, DateTimeException.class},

        {Year.of(1), 0, ChronoUnit.DAYS, null, DateTimeException.class},
        {Year.of(1), 0, ChronoUnit.WEEKS, null, DateTimeException.class},
        {Year.of(1), 0, ChronoUnit.MONTHS, null, DateTimeException.class},
    };
}
 
源代码3 项目: openjdk-jdk8u   文件: TCKYear.java
@Test
public void test_atDay_notLeapYear() {
    Year test = Year.of(2007);
    LocalDate expected = LocalDate.of(2007, 1, 1);
    for (int i = 1; i <= 365; i++) {
        assertEquals(test.atDay(i), expected);
        expected = expected.plusDays(1);
    }
}
 
源代码4 项目: openjdk-jdk8u   文件: TCKMinguoChronology.java
@Test(dataProvider="prolepticYear")
public void test_isLeapYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear);
    assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear + YDIFF).isLeap());

    MinguoDate minguo = MinguoDate.now();
    minguo = minguo.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
    if (isLeapYear) {
        assertEquals(minguo.lengthOfMonth(), 29);
    } else {
        assertEquals(minguo.lengthOfMonth(), 28);
    }
}
 
源代码5 项目: openjdk-8   文件: TCKYear.java
@DataProvider(name="isValidMonthDay")
Object[][] data_isValidMonthDay() {
    return new Object[][] {
            {Year.of(2007), MonthDay.of(6, 30), true},
            {Year.of(2008), MonthDay.of(2, 28), true},
            {Year.of(2008), MonthDay.of(2, 29), true},
            {Year.of(2009), MonthDay.of(2, 28), true},
            {Year.of(2009), MonthDay.of(2, 29), false},
            {Year.of(2009), null, false},
    };
}
 
源代码6 项目: openjdk-8-source   文件: TCKYear.java
@Test
public void test_toString() {
    for (int i = -4; i <= 2104; i++) {
        Year a = Year.of(i);
        assertEquals(a.toString(), "" + i);
    }
}
 
源代码7 项目: jdk8u-dev-jdk   文件: TCKMinguoChronology.java
@Test(dataProvider="prolepticYear")
public void test_isLeapYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear);
    assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear + YDIFF).isLeap());

    MinguoDate minguo = MinguoDate.now();
    minguo = minguo.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
    if (isLeapYear) {
        assertEquals(minguo.lengthOfMonth(), 29);
    } else {
        assertEquals(minguo.lengthOfMonth(), 28);
    }
}
 
源代码8 项目: hottub   文件: TCKYear.java
@Test
public void test_factory_int_singleton() {
    for (int i = -4; i <= 2104; i++) {
        Year test = Year.of(i);
        assertEquals(test.getValue(), i);
        assertEquals(Year.of(i), test);
    }
}
 
源代码9 项目: jdk8u_jdk   文件: TCKMinguoChronology.java
@Test(dataProvider="prolepticYear")
public void test_isLeapYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear);
    assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear + YDIFF).isLeap());

    MinguoDate minguo = MinguoDate.now();
    minguo = minguo.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
    if (isLeapYear) {
        assertEquals(minguo.lengthOfMonth(), 29);
    } else {
        assertEquals(minguo.lengthOfMonth(), 28);
    }
}
 
源代码10 项目: jdk8u-jdk   文件: TestOffsetDateTime_instants.java
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofInstant_tooLow() {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    int year = Year.MIN_VALUE - 1;
    long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970;
    Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L);
    OffsetDateTime.ofInstant(instant, ZoneOffset.UTC);
}
 
源代码11 项目: openjdk-jdk8u-backup   文件: TCKOffsetDateTime.java
@Test
public void test_compareTo_max() {
    OffsetDateTime a = OffsetDateTime.of(Year.MAX_VALUE, 12, 31, 23, 59, 0, 0, OFFSET_MONE);
    OffsetDateTime b = OffsetDateTime.of(Year.MAX_VALUE, 12, 31, 23, 59, 0, 0, OFFSET_MTWO);  // a is before b due to offset
    assertEquals(a.compareTo(b) < 0, true);
    assertEquals(b.compareTo(a) > 0, true);
    assertEquals(a.compareTo(a) == 0, true);
    assertEquals(b.compareTo(b) == 0, true);
}
 
源代码12 项目: openjdk-jdk9   文件: TCKYear.java
@Test
public void test_toString() {
    for (int i = -4; i <= 2104; i++) {
        Year a = Year.of(i);
        assertEquals(a.toString(), "" + i);
    }
}
 
源代码13 项目: j2objc   文件: TCKYear.java
@Test
public void test_plusYears() {
    assertEquals(Year.of(2007).plusYears(-1), Year.of(2006));
    assertEquals(Year.of(2007).plusYears(0), Year.of(2007));
    assertEquals(Year.of(2007).plusYears(1), Year.of(2008));
    assertEquals(Year.of(2007).plusYears(2), Year.of(2009));

    assertEquals(Year.of(Year.MAX_VALUE - 1).plusYears(1), Year.of(Year.MAX_VALUE));
    assertEquals(Year.of(Year.MAX_VALUE).plusYears(0), Year.of(Year.MAX_VALUE));

    assertEquals(Year.of(Year.MIN_VALUE + 1).plusYears(-1), Year.of(Year.MIN_VALUE));
    assertEquals(Year.of(Year.MIN_VALUE).plusYears(0), Year.of(Year.MIN_VALUE));
}
 
源代码14 项目: TencentKona-8   文件: TCKYear.java
@Test
public void test_length() {
    assertEquals(Year.of(1999).length(), 365);
    assertEquals(Year.of(2000).length(), 366);
    assertEquals(Year.of(2001).length(), 365);

    assertEquals(Year.of(2007).length(), 365);
    assertEquals(Year.of(2008).length(), 366);
    assertEquals(Year.of(2009).length(), 365);
    assertEquals(Year.of(2010).length(), 365);
    assertEquals(Year.of(2011).length(), 365);
    assertEquals(Year.of(2012).length(), 366);

    assertEquals(Year.of(2095).length(), 365);
    assertEquals(Year.of(2096).length(), 366);
    assertEquals(Year.of(2097).length(), 365);
    assertEquals(Year.of(2098).length(), 365);
    assertEquals(Year.of(2099).length(), 365);
    assertEquals(Year.of(2100).length(), 365);
    assertEquals(Year.of(2101).length(), 365);
    assertEquals(Year.of(2102).length(), 365);
    assertEquals(Year.of(2103).length(), 365);
    assertEquals(Year.of(2104).length(), 366);
    assertEquals(Year.of(2105).length(), 365);

    assertEquals(Year.of(-500).length(), 365);
    assertEquals(Year.of(-400).length(), 366);
    assertEquals(Year.of(-300).length(), 365);
    assertEquals(Year.of(-200).length(), 365);
    assertEquals(Year.of(-100).length(), 365);
    assertEquals(Year.of(0).length(), 366);
    assertEquals(Year.of(100).length(), 365);
    assertEquals(Year.of(200).length(), 365);
    assertEquals(Year.of(300).length(), 365);
    assertEquals(Year.of(400).length(), 366);
    assertEquals(Year.of(500).length(), 365);
}
 
源代码15 项目: jdk8u-jdk   文件: TCKYear.java
@DataProvider(name="isValidMonthDay")
Object[][] data_isValidMonthDay() {
    return new Object[][] {
            {Year.of(2007), MonthDay.of(6, 30), true},
            {Year.of(2008), MonthDay.of(2, 28), true},
            {Year.of(2008), MonthDay.of(2, 29), true},
            {Year.of(2009), MonthDay.of(2, 28), true},
            {Year.of(2009), MonthDay.of(2, 29), false},
            {Year.of(2009), null, false},
    };
}
 
源代码16 项目: jdk8u_jdk   文件: TCKZonedDateTime.java
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofInstant_tooLow() {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    int year = Year.MIN_VALUE - 1;
    long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970;
    Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L);
    ZonedDateTime.ofInstant(instant, ZoneOffset.UTC);
}
 
源代码17 项目: openjdk-jdk9   文件: TCKOffsetDateTime.java
@Test
public void test_compareTo_min() {
    OffsetDateTime a = OffsetDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0, 0, 0, OFFSET_PTWO);
    OffsetDateTime b = OffsetDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0, 0, 0, OFFSET_PONE);  // a is before b due to offset
    assertEquals(a.compareTo(b) < 0, true);
    assertEquals(b.compareTo(a) > 0, true);
    assertEquals(a.compareTo(a) == 0, true);
    assertEquals(b.compareTo(b) == 0, true);
}
 
源代码18 项目: openjdk-8   文件: TCKZonedDateTime.java
@Test
public void test_with_adjuster_Year() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.with(Year.of(2007));
    assertEquals(test, ZonedDateTime.of(ldt.withYear(2007), ZONE_0100));
}
 
源代码19 项目: hottub   文件: TCKOffsetDateTime.java
@Test
public void test_compareTo_max() {
    OffsetDateTime a = OffsetDateTime.of(Year.MAX_VALUE, 12, 31, 23, 59, 0, 0, OFFSET_MONE);
    OffsetDateTime b = OffsetDateTime.of(Year.MAX_VALUE, 12, 31, 23, 59, 0, 0, OFFSET_MTWO);  // a is before b due to offset
    assertEquals(a.compareTo(b) < 0, true);
    assertEquals(b.compareTo(a) > 0, true);
    assertEquals(a.compareTo(a) == 0, true);
    assertEquals(b.compareTo(b) == 0, true);
}
 
源代码20 项目: jdk8u-jdk   文件: TCKYear.java
@Test
public void test_minusYears() {
    assertEquals(Year.of(2007).minusYears(-1), Year.of(2008));
    assertEquals(Year.of(2007).minusYears(0), Year.of(2007));
    assertEquals(Year.of(2007).minusYears(1), Year.of(2006));
    assertEquals(Year.of(2007).minusYears(2), Year.of(2005));

    assertEquals(Year.of(Year.MAX_VALUE - 1).minusYears(-1), Year.of(Year.MAX_VALUE));
    assertEquals(Year.of(Year.MAX_VALUE).minusYears(0), Year.of(Year.MAX_VALUE));

    assertEquals(Year.of(Year.MIN_VALUE + 1).minusYears(1), Year.of(Year.MIN_VALUE));
    assertEquals(Year.of(Year.MIN_VALUE).minusYears(0), Year.of(Year.MIN_VALUE));
}
 
源代码21 项目: jdk8u-jdk   文件: TCKLocalDate.java
@Test(expectedExceptions=DateTimeException.class)
public void test_minusYears_long_invalidTooSmall() {
    LocalDate.of(Year.MIN_VALUE, 1, 1).minusYears(1);
}
 
源代码22 项目: openjdk-jdk8u   文件: TCKYearMonth.java
@Test(expectedExceptions=DateTimeException.class)
public void test_plusYears_long_invalidTooSmall() {
    YearMonth test = YearMonth.of(Year.MIN_VALUE, 6);
    test.plusYears(-1);
}
 
源代码23 项目: openjdk-jdk8u   文件: TCKLocalDate.java
@Test(expectedExceptions=DateTimeException.class)
public void test_withYear_int_invalid() {
    TEST_2007_07_15.withYear(Year.MIN_VALUE - 1);
}
 
private int currentYear() {
    return Year.now()
        .getValue();
}
 
源代码25 项目: j2objc   文件: TCKYear.java
@Test(expected=NullPointerException.class)
public void test_compareTo_nullYear() {
    Year doy = null;
    Year test = Year.of(1);
    test.compareTo(doy);
}
 
源代码26 项目: hottub   文件: TCKLocalDate.java
@Test(expectedExceptions={ArithmeticException.class})
public void test_plusWeeks_invalidMaxMinusMin() {
    LocalDate.of(Year.MAX_VALUE, 12, 25).plusWeeks(Long.MIN_VALUE);
}
 
源代码27 项目: jdk8u-jdk   文件: TCKLocalDate.java
@Test
public void test_plusWeeks_minimum() {
    LocalDate t = LocalDate.of(Year.MIN_VALUE, 1, 8).plusWeeks(-1);
    LocalDate expected = LocalDate.of(Year.MIN_VALUE, 1, 1);
    assertEquals(t, expected);
}
 
源代码28 项目: openjdk-jdk8u   文件: TCKLocalDate.java
@Test(expectedExceptions=DateTimeException.class)
public void test_plusMonths_long_invalidTooLargeMaxAddMax() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.plusMonths(Long.MAX_VALUE);
}
 
源代码29 项目: TencentKona-8   文件: TCKYear.java
@Test
public void test_until_convertedType() {
    Year start = Year.of(2010);
    YearMonth end = start.plusYears(2).atMonth(Month.APRIL);
    assertEquals(start.until(end, YEARS), 2);
}
 
源代码30 项目: dragonwell8_jdk   文件: TCKLocalDateTime.java
@Test(expectedExceptions=DateTimeException.class)
public void test_plusMonths_int_invalidTooSmall() {
    createDateMidnight(Year.MIN_VALUE, 1, 1).plusMonths(-1);
}
 
 类所在包
 同包方法