Search in sources :

Example 16 with Temporal

use of java.time.temporal.Temporal in project jdk8u_jdk by JetBrains.

the class TCKOffsetTime method test_with_adjustment_AmPm.

@Test
public void test_with_adjustment_AmPm() {
    OffsetTime test = TEST_11_30_59_500_PONE.with(new TemporalAdjuster() {

        @Override
        public Temporal adjustInto(Temporal dateTime) {
            return dateTime.with(HOUR_OF_DAY, 23);
        }
    });
    assertEquals(test, OffsetTime.of(23, 30, 59, 500, OFFSET_PONE));
}
Also used : Temporal(java.time.temporal.Temporal) OffsetTime(java.time.OffsetTime) TemporalAdjuster(java.time.temporal.TemporalAdjuster) Test(org.testng.annotations.Test)

Example 17 with Temporal

use of java.time.temporal.Temporal in project jdk8u_jdk by JetBrains.

the class TCKOffsetTime method test_with_adjustment.

//-----------------------------------------------------------------------
// with(WithAdjuster)
//-----------------------------------------------------------------------
@Test
public void test_with_adjustment() {
    final OffsetTime sample = OffsetTime.of(23, 5, 0, 0, OFFSET_PONE);
    TemporalAdjuster adjuster = new TemporalAdjuster() {

        @Override
        public Temporal adjustInto(Temporal dateTime) {
            return sample;
        }
    };
    assertEquals(TEST_11_30_59_500_PONE.with(adjuster), sample);
}
Also used : Temporal(java.time.temporal.Temporal) OffsetTime(java.time.OffsetTime) TemporalAdjuster(java.time.temporal.TemporalAdjuster) Test(org.testng.annotations.Test)

Example 18 with Temporal

use of java.time.temporal.Temporal in project jdk8u_jdk by JetBrains.

the class TCKYear method test_adjustDate.

//-----------------------------------------------------------------------
// adjustInto()
//-----------------------------------------------------------------------
@Test
public void test_adjustDate() {
    LocalDate base = LocalDate.of(2007, 2, 12);
    for (int i = -4; i <= 2104; i++) {
        Temporal result = Year.of(i).adjustInto(base);
        assertEquals(result, LocalDate.of(i, 2, 12));
    }
}
Also used : Temporal(java.time.temporal.Temporal) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 19 with Temporal

use of java.time.temporal.Temporal in project jdk8u_jdk by JetBrains.

the class TCKYear method test_with_TemporalAdjuster.

//-----------------------------------------------------------------------
// with(TemporalAdjuster)
//-----------------------------------------------------------------------
@Test
public void test_with_TemporalAdjuster() {
    Year base = Year.of(-10);
    for (int i = -4; i <= 2104; i++) {
        Temporal result = base.with(Year.of(i));
        assertEquals(result, Year.of(i));
    }
}
Also used : Year(java.time.Year) Temporal(java.time.temporal.Temporal) Test(org.testng.annotations.Test)

Example 20 with Temporal

use of java.time.temporal.Temporal in project jdk8u_jdk by JetBrains.

the class TCKChronoUnit method test_unitAndTemporal.

@Test(dataProvider = "unitAndTemporal")
public void test_unitAndTemporal(ChronoUnit unit, Temporal base, boolean isSupportedBy, long amount, Temporal target) {
    assertEquals(unit.isSupportedBy(base), isSupportedBy);
    if (isSupportedBy) {
        Temporal result = unit.addTo(base, amount);
        assertEquals(result, target);
        assertEquals(unit.between(base, result), amount);
    }
}
Also used : Temporal(java.time.temporal.Temporal) Test(org.testng.annotations.Test)

Aggregations

Temporal (java.time.temporal.Temporal)24 Test (org.testng.annotations.Test)24 TemporalAmount (java.time.temporal.TemporalAmount)7 TemporalUnit (java.time.temporal.TemporalUnit)7 TemporalAdjuster (java.time.temporal.TemporalAdjuster)6 DateTimeException (java.time.DateTimeException)5 DateTimeParseException (java.time.format.DateTimeParseException)5 ArrayList (java.util.ArrayList)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 LocalDate (java.time.LocalDate)2 LocalTime (java.time.LocalTime)2 OffsetTime (java.time.OffsetTime)2 ChronoLocalDate (java.time.chrono.ChronoLocalDate)2 ChronoPeriod (java.time.chrono.ChronoPeriod)2 UnsupportedTemporalTypeException (java.time.temporal.UnsupportedTemporalTypeException)2 Duration (java.time.Duration)1 LocalDateTime (java.time.LocalDateTime)1 OffsetDateTime (java.time.OffsetDateTime)1 Year (java.time.Year)1 MINUTE_OF_HOUR (java.time.temporal.ChronoField.MINUTE_OF_HOUR)1