Search in sources :

Example 16 with TemporalAmount

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

the class TCKLocalTime method test_minus_TemporalAmount_wrap.

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

Example 17 with TemporalAmount

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

the class TCKPeriod method factory_from_TemporalAmount_Years_tooBig.

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

        @Override
        public long get(TemporalUnit unit) {
            return ((long) (Integer.MAX_VALUE)) + 1;
        }

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

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

        @Override
        public Temporal subtractFrom(Temporal temporal) {
            throw new UnsupportedOperationException();
        }
    };
    Period.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 18 with TemporalAmount

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

the class TCKPeriod method factory_from_TemporalAmount_YearsDays.

@Test
public void factory_from_TemporalAmount_YearsDays() {
    TemporalAmount amount = new TemporalAmount() {

        @Override
        public long get(TemporalUnit unit) {
            if (unit == YEARS) {
                return 23;
            } else {
                return 45;
            }
        }

        @Override
        public List<TemporalUnit> getUnits() {
            List<TemporalUnit> list = new ArrayList<>();
            list.add(YEARS);
            list.add(DAYS);
            return list;
        }

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

        @Override
        public Temporal subtractFrom(Temporal temporal) {
            throw new UnsupportedOperationException();
        }
    };
    assertPeriod(Period.from(amount), 23, 0, 45);
}
Also used : Temporal(java.time.temporal.Temporal) TemporalUnit(java.time.temporal.TemporalUnit) TemporalAmount(java.time.temporal.TemporalAmount) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 19 with TemporalAmount

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

the class TCKPeriod method test_plus_TemporalAmount_DaysHours.

@Test(expectedExceptions = DateTimeException.class)
public void test_plus_TemporalAmount_DaysHours() {
    TemporalAmount amount = new TemporalAmount() {

        @Override
        public long get(TemporalUnit unit) {
            if (unit == DAYS) {
                return 1;
            } else {
                return 2;
            }
        }

        @Override
        public List<TemporalUnit> getUnits() {
            List<TemporalUnit> list = new ArrayList<>();
            list.add(DAYS);
            list.add(HOURS);
            return list;
        }

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

        @Override
        public Temporal subtractFrom(Temporal temporal) {
            throw new UnsupportedOperationException();
        }
    };
    pymd(4, 5, 6).plus(amount);
}
Also used : Temporal(java.time.temporal.Temporal) TemporalUnit(java.time.temporal.TemporalUnit) TemporalAmount(java.time.temporal.TemporalAmount) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 20 with TemporalAmount

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

the class TCKPeriod method factory_from_TemporalAmount_Period.

//-----------------------------------------------------------------------
// from(TemporalAmount)
//-----------------------------------------------------------------------
@Test
public void factory_from_TemporalAmount_Period() {
    TemporalAmount amount = Period.of(1, 2, 3);
    assertPeriod(Period.from(amount), 1, 2, 3);
}
Also used : 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