Search in sources :

Example 6 with TemporalAmount

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

the class TCKDuration method factory_from_TemporalAmount_Duration.

//-----------------------------------------------------------------------
// from(TemporalAmount)
//-----------------------------------------------------------------------
@Test
public void factory_from_TemporalAmount_Duration() {
    TemporalAmount amount = Duration.ofHours(3);
    assertEquals(Duration.from(amount), Duration.ofHours(3));
}
Also used : TemporalAmount(java.time.temporal.TemporalAmount) Test(org.testng.annotations.Test)

Example 7 with TemporalAmount

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

the class TCKDuration method factory_from_TemporalAmount_Minutes_tooBig.

@Test(expectedExceptions = ArithmeticException.class)
public void factory_from_TemporalAmount_Minutes_tooBig() {
    TemporalAmount amount = new TemporalAmount() {

        @Override
        public long get(TemporalUnit unit) {
            return (Long.MAX_VALUE / 60) + 2;
        }

        @Override
        public List<TemporalUnit> getUnits() {
            return Collections.<TemporalUnit>singletonList(MINUTES);
        }

        @Override
        public Temporal addTo(Temporal temporal) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Temporal subtractFrom(Temporal temporal) {
            throw new UnsupportedOperationException();
        }
    };
    Duration.from(amount);
}
Also used : Temporal(java.time.temporal.Temporal) TemporalUnit(java.time.temporal.TemporalUnit) TemporalAmount(java.time.temporal.TemporalAmount) Test(org.testng.annotations.Test)

Example 8 with TemporalAmount

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

the class TCKLocalTime method test_plus_TemporalAmount_wrap.

@Test
public void test_plus_TemporalAmount_wrap() {
    TemporalAmount p = MockSimplePeriod.of(1, HOURS);
    LocalTime t = LocalTime.of(23, 30).plus(p);
    assertEquals(t, LocalTime.of(0, 30));
}
Also used : LocalTime(java.time.LocalTime) TemporalAmount(java.time.temporal.TemporalAmount) Test(org.testng.annotations.Test)

Example 9 with TemporalAmount

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

the class TCKLocalTime method test_plus_TemporalAmount_dateNotAllowed.

@Test(expectedExceptions = DateTimeException.class)
public void test_plus_TemporalAmount_dateNotAllowed() {
    TemporalAmount period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
    TEST_12_30_40_987654321.plus(period);
}
Also used : TemporalAmount(java.time.temporal.TemporalAmount) Test(org.testng.annotations.Test)

Example 10 with TemporalAmount

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

the class TCKLocalTime method test_minus_TemporalAmount_negativeMinutes.

@Test
public void test_minus_TemporalAmount_negativeMinutes() {
    TemporalAmount period = MockSimplePeriod.of(-25, ChronoUnit.MINUTES);
    LocalTime t = TEST_12_30_40_987654321.minus(period);
    assertEquals(t, LocalTime.of(12, 55, 40, 987654321));
}
Also used : LocalTime(java.time.LocalTime) TemporalAmount(java.time.temporal.TemporalAmount) Test(org.testng.annotations.Test)

Aggregations

TemporalAmount (java.time.temporal.TemporalAmount)25 Test (org.testng.annotations.Test)25 LocalTime (java.time.LocalTime)8 Temporal (java.time.temporal.Temporal)7 TemporalUnit (java.time.temporal.TemporalUnit)7 LocalDate (java.time.LocalDate)6 Chronology (java.time.chrono.Chronology)6 HijrahChronology (java.time.chrono.HijrahChronology)6 IsoChronology (java.time.chrono.IsoChronology)6 JapaneseChronology (java.time.chrono.JapaneseChronology)6 MinguoChronology (java.time.chrono.MinguoChronology)6 ThaiBuddhistChronology (java.time.chrono.ThaiBuddhistChronology)6 ArrayList (java.util.ArrayList)5 ChronoLocalDate (java.time.chrono.ChronoLocalDate)2 Duration (java.time.Duration)1