Search in sources :

Example 26 with LocalTime

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

the class TimeTests method test09.

/*
     * Validate that a Time made from a toLocalTime() LocalTime are equal
     */
@Test
public void test09() {
    Time t = Time.valueOf("08:30:59");
    Time t2 = Time.valueOf(t.toLocalTime());
    assertTrue(t.equals(t2), "Error t != t2");
}
Also used : Time(java.sql.Time) LocalTime(java.time.LocalTime) Test(org.testng.annotations.Test) BaseTest(util.BaseTest)

Example 27 with LocalTime

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

the class TCKLocalTime method test_with_longTemporalField_minuteOfHour.

// Returns a {@code LocalTime} with the specified minute-of-hour.
// The hour, second-of-minute and nano-of-second will be unchanged.
@Test
public void test_with_longTemporalField_minuteOfHour() {
    for (long i : testPoints(60)) {
        LocalTime test = TEST_12_30_40_987654321.with(MINUTE_OF_HOUR, i);
        assertEquals(test.get(MINUTE_OF_HOUR), i);
        assertEquals(test.get(HOUR_OF_DAY), TEST_12_30_40_987654321.get(HOUR_OF_DAY));
        assertEquals(test.get(SECOND_OF_MINUTE), TEST_12_30_40_987654321.get(SECOND_OF_MINUTE));
        assertEquals(test.get(NANO_OF_SECOND), TEST_12_30_40_987654321.get(NANO_OF_SECOND));
    }
}
Also used : LocalTime(java.time.LocalTime) Test(org.testng.annotations.Test)

Example 28 with LocalTime

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

the class TCKLocalTime method test_plusHours_fromZero.

@Test
public void test_plusHours_fromZero() {
    LocalTime base = LocalTime.MIDNIGHT;
    for (int i = -50; i < 50; i++) {
        LocalTime t = base.plusHours(i);
        assertEquals(t.getHour(), (i + 72) % 24);
    }
}
Also used : LocalTime(java.time.LocalTime) Test(org.testng.annotations.Test)

Example 29 with LocalTime

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

the class TCKLocalTime method test_plusNanos_halfABillion.

//-----------------------------------------------------------------------
// plusNanos()
//-----------------------------------------------------------------------
@Test
public void test_plusNanos_halfABillion() {
    LocalTime t = LocalTime.MIDNIGHT;
    int hour = 0;
    int min = 0;
    int sec = 0;
    int nanos = 0;
    for (long i = 0; i < 3700 * 1000000000L; i += 500000000) {
        t = t.plusNanos(500000000);
        nanos += 500000000;
        if (nanos == 1000000000) {
            sec++;
            nanos = 0;
        }
        if (sec == 60) {
            min++;
            sec = 0;
        }
        if (min == 60) {
            hour++;
            min = 0;
        }
        assertEquals(t.getHour(), hour);
        assertEquals(t.getMinute(), min);
        assertEquals(t.getSecond(), sec);
        assertEquals(t.getNano(), nanos);
    }
}
Also used : LocalTime(java.time.LocalTime) Test(org.testng.annotations.Test)

Example 30 with LocalTime

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

the class TCKLocalTime method factory_parse_formatter.

//-----------------------------------------------------------------------
// parse(DateTimeFormatter)
//-----------------------------------------------------------------------
@Test
public void factory_parse_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("H m s");
    LocalTime test = LocalTime.parse("14 30 40", f);
    assertEquals(test, LocalTime.of(14, 30, 40));
}
Also used : LocalTime(java.time.LocalTime) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Aggregations

LocalTime (java.time.LocalTime)188 Test (org.testng.annotations.Test)164 LocalDate (java.time.LocalDate)21 LocalDateTime (java.time.LocalDateTime)20 Instant (java.time.Instant)11 Clock (java.time.Clock)8 TemporalAmount (java.time.temporal.TemporalAmount)8 Test (org.junit.Test)8 OffsetDateTime (java.time.OffsetDateTime)7 Time (java.sql.Time)6 OffsetTime (java.time.OffsetTime)5 DateTimeFormatter (java.time.format.DateTimeFormatter)5 ZonedDateTime (java.time.ZonedDateTime)4 ZoneId (java.time.ZoneId)3 TemporalAccessor (java.time.temporal.TemporalAccessor)3 BaseTest (util.BaseTest)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 ZoneOffset (java.time.ZoneOffset)2 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)2