Search in sources :

Example 26 with Year

use of java.time.Year in project jdk8u_jdk by JetBrains.

the class TCKYear method now_ZoneId.

@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    Year expected = Year.now(Clock.system(zone));
    Year test = Year.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = Year.now(Clock.system(zone));
        test = Year.now(zone);
    }
    assertEquals(test, expected);
}
Also used : ZoneId(java.time.ZoneId) Year(java.time.Year) Test(org.testng.annotations.Test)

Example 27 with Year

use of java.time.Year in project jdk8u_jdk by JetBrains.

the class TCKYear method test_minusYear_zero_equals.

@Test
public void test_minusYear_zero_equals() {
    Year base = Year.of(2007);
    assertEquals(base.minusYears(0), base);
}
Also used : Year(java.time.Year) Test(org.testng.annotations.Test)

Example 28 with Year

use of java.time.Year in project jdk8u_jdk by JetBrains.

the class TCKYear method test_factory_int_singleton.

//-----------------------------------------------------------------------
@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);
    }
}
Also used : Year(java.time.Year) Test(org.testng.annotations.Test)

Example 29 with Year

use of java.time.Year in project jdk8u_jdk by JetBrains.

the class TCKYear method test_with.

//-----------------------------------------------------------------------
// with(TemporalField, long)
//-----------------------------------------------------------------------
@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);
}
Also used : Year(java.time.Year) Test(org.testng.annotations.Test)

Example 30 with Year

use of java.time.Year in project jdk8u_jdk by JetBrains.

the class TCKYear method test_atMonth_int.

//-----------------------------------------------------------------------
// atMonth(int)
//-----------------------------------------------------------------------
@Test
public void test_atMonth_int() {
    Year test = Year.of(2008);
    assertEquals(test.atMonth(6), YearMonth.of(2008, 6));
}
Also used : Year(java.time.Year) Test(org.testng.annotations.Test)

Aggregations

Year (java.time.Year)34 Test (org.testng.annotations.Test)33 LocalDate (java.time.LocalDate)3 YearMonth (java.time.YearMonth)2 Clock (java.time.Clock)1 DateTimeException (java.time.DateTimeException)1 Instant (java.time.Instant)1 ZoneId (java.time.ZoneId)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 DateTimeParseException (java.time.format.DateTimeParseException)1 Temporal (java.time.temporal.Temporal)1 TemporalAccessor (java.time.temporal.TemporalAccessor)1 UnsupportedTemporalTypeException (java.time.temporal.UnsupportedTemporalTypeException)1