Search in sources :

Example 1 with TemporalAmount

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

the class TCKChronoLocalDateTime method test_badMinusAdjusterChrono.

@Test(dataProvider = "calendars")
public void test_badMinusAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
        TemporalAmount adjuster = new FixedAdjuster(cdt2);
        if (chrono != chrono2) {
            try {
                cdt.minus(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException, " + "required: " + cdt + ", supplied: " + cdt2);
            } catch (ClassCastException cce) {
            // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDateTime<?> result = cdt.minus(adjuster);
            assertEquals(result, cdt2, "WithAdjuster failed to replace date");
        }
    }
}
Also used : TemporalAmount(java.time.temporal.TemporalAmount) HijrahChronology(java.time.chrono.HijrahChronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) MinguoChronology(java.time.chrono.MinguoChronology) JapaneseChronology(java.time.chrono.JapaneseChronology) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 2 with TemporalAmount

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

the class TCKLocalTime method test_minus_TemporalAmount_positiveHours.

//-----------------------------------------------------------------------
// minus(TemporalAmount)
//-----------------------------------------------------------------------
@Test
public void test_minus_TemporalAmount_positiveHours() {
    TemporalAmount period = MockSimplePeriod.of(7, ChronoUnit.HOURS);
    LocalTime t = TEST_12_30_40_987654321.minus(period);
    assertEquals(t, LocalTime.of(5, 30, 40, 987654321));
}
Also used : LocalTime(java.time.LocalTime) TemporalAmount(java.time.temporal.TemporalAmount) Test(org.testng.annotations.Test)

Example 3 with TemporalAmount

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

the class TCKLocalTime method test_minus_TemporalAmount_zero.

@Test
public void test_minus_TemporalAmount_zero() {
    TemporalAmount period = Period.ZERO;
    LocalTime t = TEST_12_30_40_987654321.minus(period);
    assertEquals(t, TEST_12_30_40_987654321);
}
Also used : LocalTime(java.time.LocalTime) TemporalAmount(java.time.temporal.TemporalAmount) Test(org.testng.annotations.Test)

Example 4 with TemporalAmount

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

the class TCKPeriod method factory_from_TemporalAmount_DaysHours.

@Test(expectedExceptions = DateTimeException.class)
public void factory_from_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();
        }
    };
    Period.from(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 5 with TemporalAmount

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

the class TCKDuration method factory_from_TemporalAmount_DaysNanos.

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

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

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

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

        @Override
        public Temporal subtractFrom(Temporal temporal) {
            throw new UnsupportedOperationException();
        }
    };
    Duration t = Duration.from(amount);
    assertEquals(t.getSeconds(), 23 * 86400);
    assertEquals(t.getNano(), 45);
}
Also used : Temporal(java.time.temporal.Temporal) TemporalUnit(java.time.temporal.TemporalUnit) TemporalAmount(java.time.temporal.TemporalAmount) ArrayList(java.util.ArrayList) Duration(java.time.Duration) 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