Search in sources :

Example 41 with OffsetTime

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

the class TCKOffsetTime method test_equals_false_hour_differs.

@Test(dataProvider = "sampleTimes")
public void test_equals_false_hour_differs(int h, int m, int s, int n, ZoneOffset ignored) {
    h = (h == 23 ? 22 : h);
    OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE);
    OffsetTime b = OffsetTime.of(h + 1, m, s, n, OFFSET_PONE);
    assertEquals(a.equals(b), false);
}
Also used : OffsetTime(java.time.OffsetTime) Test(org.testng.annotations.Test)

Example 42 with OffsetTime

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

the class TCKOffsetTime method factory_ofInstant_allSecsInDay.

@Test
public void factory_ofInstant_allSecsInDay() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i, 8);
        OffsetTime test = OffsetTime.ofInstant(instant, ZoneOffset.UTC);
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 8);
    }
}
Also used : OffsetTime(java.time.OffsetTime) Instant(java.time.Instant) Test(org.testng.annotations.Test)

Example 43 with OffsetTime

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

the class TCKOffsetTime method now.

//-----------------------------------------------------------------------
// now()
//-----------------------------------------------------------------------
@Test
public void now() {
    ZonedDateTime nowDT = ZonedDateTime.now();
    OffsetTime expected = OffsetTime.now(Clock.systemDefaultZone());
    OffsetTime test = OffsetTime.now();
    long diff = Math.abs(test.toLocalTime().toNanoOfDay() - expected.toLocalTime().toNanoOfDay());
    // less than 0.1 secs
    assertTrue(diff < 100000000);
    assertEquals(test.getOffset(), nowDT.getOffset());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) OffsetTime(java.time.OffsetTime) Test(org.testng.annotations.Test)

Example 44 with OffsetTime

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

the class TCKOffsetTime method test_compareTo_hourDifference.

@Test
public void test_compareTo_hourDifference() {
    OffsetTime a = OffsetTime.of(10, 0, 0, 0, OFFSET_PONE);
    // a is before b despite being same time-line time
    OffsetTime b = OffsetTime.of(11, 0, 0, 0, OFFSET_PTWO);
    assertEquals(a.compareTo(b) < 0, true);
    assertEquals(b.compareTo(a) > 0, true);
    assertEquals(a.compareTo(a) == 0, true);
    assertEquals(b.compareTo(b) == 0, true);
    assertEquals(convertInstant(a).compareTo(convertInstant(b)) == 0, true);
}
Also used : OffsetTime(java.time.OffsetTime) Test(org.testng.annotations.Test)

Example 45 with OffsetTime

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

the class TCKOffsetTime method test_withSecond_normal.

//-----------------------------------------------------------------------
// withSecond()
//-----------------------------------------------------------------------
@Test
public void test_withSecond_normal() {
    OffsetTime base = OffsetTime.of(11, 30, 59, 0, OFFSET_PONE);
    OffsetTime test = base.withSecond(15);
    assertEquals(test, OffsetTime.of(11, 30, 15, 0, OFFSET_PONE));
}
Also used : OffsetTime(java.time.OffsetTime) Test(org.testng.annotations.Test)

Aggregations

OffsetTime (java.time.OffsetTime)99 Test (org.testng.annotations.Test)86 ZonedDateTime (java.time.ZonedDateTime)9 LocalTime (java.time.LocalTime)8 Instant (java.time.Instant)7 OffsetDateTime (java.time.OffsetDateTime)7 Time (java.sql.Time)6 LocalDate (java.time.LocalDate)6 LocalDateTime (java.time.LocalDateTime)6 Test (org.junit.Test)6 Date (java.sql.Date)3 ResultSet (java.sql.ResultSet)3 Clock (java.time.Clock)3 PostgresUtils.toPGArrayString (org.jooq.util.postgres.PostgresUtils.toPGArrayString)3 BigDecimal (java.math.BigDecimal)2 PreparedStatement (java.sql.PreparedStatement)2 Timestamp (java.sql.Timestamp)2 Duration (java.time.Duration)2 Period (java.time.Period)2 ZoneId (java.time.ZoneId)2