Search in sources :

Example 66 with OffsetDateTime

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

the class TCKOffsetDateTime method test_with_adjustment_ZoneOffset.

@Test
public void test_with_adjustment_ZoneOffset() {
    OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(OFFSET_PTWO);
    assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 500), OFFSET_PTWO));
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Test(org.testng.annotations.Test)

Example 67 with OffsetDateTime

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

the class TCKOffsetDateTime method test_toEpochSecond_afterEpoch.

//-----------------------------------------------------------------------
// toEpochSecond()
//-----------------------------------------------------------------------
@Test
public void test_toEpochSecond_afterEpoch() {
    for (int i = 0; i < 100000; i++) {
        OffsetDateTime a = OffsetDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).plusSeconds(i);
        assertEquals(a.toEpochSecond(), i);
    }
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Test(org.testng.annotations.Test)

Example 68 with OffsetDateTime

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

the class TCKOffsetDateTime method test_compareTo_bothNanos.

@Test
public void test_compareTo_bothNanos() {
    OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 20, 40, 4, OFFSET_PTWO);
    // a is before b on instant scale
    OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 10, 20, 40, 5, OFFSET_PONE);
    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(a.toInstant().compareTo(b.toInstant()) < 0, true);
    assertEquals(OffsetDateTime.timeLineOrder().compare(a, b) < 0, true);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Test(org.testng.annotations.Test)

Example 69 with OffsetDateTime

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

the class TCKOffsetDateTime method test_getLong_TemporalField.

@Test
public void test_getLong_TemporalField() {
    OffsetDateTime test = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(12, 30, 40, 987654321), OFFSET_PONE);
    assertEquals(test.getLong(ChronoField.YEAR), 2008);
    assertEquals(test.getLong(ChronoField.MONTH_OF_YEAR), 6);
    assertEquals(test.getLong(ChronoField.DAY_OF_MONTH), 30);
    assertEquals(test.getLong(ChronoField.DAY_OF_WEEK), 1);
    assertEquals(test.getLong(ChronoField.DAY_OF_YEAR), 182);
    assertEquals(test.getLong(ChronoField.HOUR_OF_DAY), 12);
    assertEquals(test.getLong(ChronoField.MINUTE_OF_HOUR), 30);
    assertEquals(test.getLong(ChronoField.SECOND_OF_MINUTE), 40);
    assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 987654321);
    assertEquals(test.getLong(ChronoField.HOUR_OF_AMPM), 0);
    assertEquals(test.getLong(ChronoField.AMPM_OF_DAY), 1);
    assertEquals(test.getLong(ChronoField.INSTANT_SECONDS), test.toEpochSecond());
    assertEquals(test.getLong(ChronoField.OFFSET_SECONDS), 3600);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Test(org.testng.annotations.Test)

Example 70 with OffsetDateTime

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

the class TCKOffsetDateTime method now_Clock_offsets.

@Test
public void now_Clock_offsets() {
    OffsetDateTime base = OffsetDateTime.of(1970, 1, 1, 12, 0, 0, 0, ZoneOffset.UTC);
    for (int i = -9; i < 15; i++) {
        ZoneOffset offset = ZoneOffset.ofHours(i);
        Clock clock = Clock.fixed(base.toInstant(), offset);
        OffsetDateTime test = OffsetDateTime.now(clock);
        assertEquals(test.getHour(), (12 + i) % 24);
        assertEquals(test.getMinute(), 0);
        assertEquals(test.getSecond(), 0);
        assertEquals(test.getNano(), 0);
        assertEquals(test.getOffset(), offset);
    }
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Clock(java.time.Clock) ZoneOffset(java.time.ZoneOffset) Test(org.testng.annotations.Test)

Aggregations

OffsetDateTime (java.time.OffsetDateTime)199 Test (org.testng.annotations.Test)139 Test (org.junit.Test)26 Instant (java.time.Instant)22 ZonedDateTime (java.time.ZonedDateTime)18 LocalDateTime (java.time.LocalDateTime)13 LocalDate (java.time.LocalDate)12 LocalTime (java.time.LocalTime)11 OffsetTime (java.time.OffsetTime)7 Map (java.util.Map)7 Timestamp (java.sql.Timestamp)6 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)6 ZoneOffset (java.time.ZoneOffset)5 Date (java.sql.Date)4 Clock (java.time.Clock)4 Duration (java.time.Duration)4 DateTimeFormatter (java.time.format.DateTimeFormatter)4 Collections.emptyMap (java.util.Collections.emptyMap)4 UUID (java.util.UUID)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4