Java Code Examples for java.time.Year#of()

The following examples show how to use java.time.Year#of() . 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: XmlAdaptersTest.java    From threeten-jaxb with Apache License 2.0 6 votes vote down vote up
XmlAdaptersTest() throws JAXBException {
    jaxbContext = JAXBContext.newInstance(Bean.class);

    final Bean expectedBean = new Bean();
    expectedBean.duration = Duration.ofDays(2).plusHours(3).plusMinutes(4);
    expectedBean.instant = LocalDateTime.of(2007, 12, 3, 10, 15, 30)
            .toInstant(ZoneOffset.UTC);
    expectedBean.localDateTime = LocalDateTime.of(2007, 12, 3, 10, 15, 30);
    expectedBean.localDate = LocalDate.of(2014, 12, 31);
    expectedBean.localTime = LocalTime.of(10, 15, 30);
    expectedBean.monthDay = MonthDay.of(Month.DECEMBER, 3);
    expectedBean.offsetDateTime = OffsetDateTime
            .of(2007, 12, 3, 10, 15, 30, 0, ZoneOffset.ofHours(1));
    expectedBean.offsetTime = OffsetTime
            .of(10, 15, 30, 0, ZoneOffset.ofHours(1));
    expectedBean.period = Period.of(1, 2, 25);
    expectedBean.year = Year.of(-2014);
    expectedBean.yearMonth = YearMonth.of(2014, 12);
    expectedBean.zoneId = ZoneId.of("America/New_York");
    expectedBean.zoneOffset = ZoneOffset.ofHoursMinutes(-12, 0);
    expectedBean.zonedDateTime = ZonedDateTime
            .of(2007, 12, 3, 10, 15, 30, 0, ZoneId.of("Europe/Paris"));
    this.expectedBean = expectedBean;

    this.expectedMarshalledBean = getClass().getResource("expectedBean.xml");
}
 
Example 2
Source File: TCKYear.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_with() {
    Year base = Year.of(5);
    Year result = base.with(ChronoField.ERA, 0);
    assertEquals(result, base.with(IsoEra.of(0)));

    int prolepticYear = IsoChronology.INSTANCE.prolepticYear(IsoEra.of(0), 5);
    assertEquals(result.get(ChronoField.ERA), 0);
    assertEquals(result.get(ChronoField.YEAR), prolepticYear);
    assertEquals(result.get(ChronoField.YEAR_OF_ERA), 5);

    result = base.with(ChronoField.YEAR, 10);
    assertEquals(result.get(ChronoField.ERA), base.get(ChronoField.ERA));
    assertEquals(result.get(ChronoField.YEAR), 10);
    assertEquals(result.get(ChronoField.YEAR_OF_ERA), 10);

    result = base.with(ChronoField.YEAR_OF_ERA, 20);
    assertEquals(result.get(ChronoField.ERA), base.get(ChronoField.ERA));
    assertEquals(result.get(ChronoField.YEAR), 20);
    assertEquals(result.get(ChronoField.YEAR_OF_ERA), 20);
}
 
Example 3
Source File: TCKYear.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="goodParseData")
Object[][] provider_goodParseData() {
    return new Object[][] {
            {"0000", Year.of(0)},
            {"9999", Year.of(9999)},
            {"2000", Year.of(2000)},

            {"+12345678", Year.of(12345678)},
            {"+123456", Year.of(123456)},
            {"-1234", Year.of(-1234)},
            {"-12345678", Year.of(-12345678)},

            {"+" + Year.MAX_VALUE, Year.of(Year.MAX_VALUE)},
            {"" + Year.MIN_VALUE, Year.of(Year.MIN_VALUE)},
    };
}
 
Example 4
Source File: TCKYear.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@DataProvider(name="goodParseData")
Object[][] provider_goodParseData() {
    return new Object[][] {
            {"0000", Year.of(0)},
            {"9999", Year.of(9999)},
            {"2000", Year.of(2000)},

            {"+12345678", Year.of(12345678)},
            {"+123456", Year.of(123456)},
            {"-1234", Year.of(-1234)},
            {"-12345678", Year.of(-12345678)},

            {"+" + Year.MAX_VALUE, Year.of(Year.MAX_VALUE)},
            {"" + Year.MIN_VALUE, Year.of(Year.MIN_VALUE)},
    };
}
 
Example 5
Source File: TCKYear.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@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},
    };
}
 
Example 6
Source File: TCKYear.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example 7
Source File: Copyright.java    From jpx with Apache License 2.0 5 votes vote down vote up
static Copyright read(final DataInput in) throws IOException {
	return new Copyright(
		IO.readString(in),
		in.readBoolean() ? Year.of(IO.readInt(in)) : null,
		parseURI(IO.readNullableString(in))
	);
}
 
Example 8
Source File: TCKYear.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_atMonth_int_invalidMonth() {
    Year test = Year.of(2008);
    test.atMonth(13);
}
 
Example 9
Source File: YearCodec.java    From r2dbc-mysql with Apache License 2.0 4 votes vote down vote up
@Override
public Year decode(ByteBuf value, FieldInformation info, Class<?> target, boolean binary, CodecContext context) {
    return binary ? Year.of(value.readShortLE()) : Year.of(IntegerCodec.parse(value));
}
 
Example 10
Source File: TCKYear.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_plusYear_zero_equals() {
    Year base = Year.of(2007);
    assertEquals(base.plusYears(0), base);
}
 
Example 11
Source File: TCKYear.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_atMonth_nullMonth() {
    Year test = Year.of(2008);
    test.atMonth((Month) null);
}
 
Example 12
Source File: TCKYear.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_atMonth_int() {
    Year test = Year.of(2008);
    assertEquals(test.atMonth(6), YearMonth.of(2008, 6));
}
 
Example 13
Source File: TCKYear.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_until_invalidType() {
    Year start = Year.of(2010);
    start.until(LocalTime.of(11, 30), YEARS);
}
 
Example 14
Source File: TCKDateTimeFormatters.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_print_isoOrdinalDate_missingField() {
    TemporalAccessor test = Year.of(2008);
    DateTimeFormatter.ISO_ORDINAL_DATE.format(test);
}
 
Example 15
Source File: TCKDateTimeFormatters.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_print_isoOrdinalDate_missingField() {
    TemporalAccessor test = Year.of(2008);
    DateTimeFormatter.ISO_ORDINAL_DATE.format(test);
}
 
Example 16
Source File: TCKYear.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test
public void test_atMonth_int() {
    Year test = Year.of(2008);
    assertEquals(test.atMonth(6), YearMonth.of(2008, 6));
}
 
Example 17
Source File: TCKYear.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_with_BadTemporalAdjuster() {
    Year test = Year.of(1);
    test.with(LocalTime.of(18, 1, 2));
}
 
Example 18
Source File: TCKYear.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void test_atMonthDay_nullMonthDay() {
    Year test = Year.of(2008);
    test.atMonthDay((MonthDay) null);
}
 
Example 19
Source File: Apian2Projection.java    From JMapProjLib with Apache License 2.0 4 votes vote down vote up
@Override
public Year getYear() {
    return Year.of(1524);
}
 
Example 20
Source File: TCKYear.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=DateTimeException.class)
public void test_atMonth_int_invalidMonth() {
    Year test = Year.of(2008);
    test.atMonth(13);
}