Search in sources :

Example 86 with OffsetDateTime

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

the class TCKZonedDateTime method test_with_adjuster_ensureOffsetDateTimeConsistent.

@Test(dataProvider = "withFieldLong")
public void test_with_adjuster_ensureOffsetDateTimeConsistent(ZonedDateTime base, TemporalField setField, int setValue, ZonedDateTime expected) {
    if (setField == OFFSET_SECONDS) {
        OffsetDateTime odt = base.toOffsetDateTime().with(setField, setValue);
        assertEquals(base.with(odt), expected);
    }
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Test(org.testng.annotations.Test)

Example 87 with OffsetDateTime

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

the class TestOffsetDateTime_instants method factory_ofInstant_minWithMinOffset.

//-----------------------------------------------------------------------
public void factory_ofInstant_minWithMinOffset() {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    int year = Year.MIN_VALUE;
    long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970;
    Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L - OFFSET_MIN.getTotalSeconds());
    OffsetDateTime test = OffsetDateTime.ofInstant(instant, OFFSET_MIN);
    assertEquals(test.getYear(), Year.MIN_VALUE);
    assertEquals(test.getMonth().getValue(), 1);
    assertEquals(test.getDayOfMonth(), 1);
    assertEquals(test.getOffset(), OFFSET_MIN);
    assertEquals(test.getHour(), 0);
    assertEquals(test.getMinute(), 0);
    assertEquals(test.getSecond(), 0);
    assertEquals(test.getNano(), 0);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Instant(java.time.Instant)

Example 88 with OffsetDateTime

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

the class TestOffsetDateTime_instants method test_toEpochSecond_19700101_oneNano.

public void test_toEpochSecond_19700101_oneNano() {
    OffsetDateTime dt = OffsetDateTime.of(LocalDate.of(1970, 1, 1), LocalTime.of(0, 0, 0, 1), ZoneOffset.UTC);
    assertEquals(dt.toEpochSecond(), 0);
}
Also used : OffsetDateTime(java.time.OffsetDateTime)

Example 89 with OffsetDateTime

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

the class TestOffsetDateTime_instants method test_toEpochSecond_19700102.

public void test_toEpochSecond_19700102() {
    OffsetDateTime dt = OffsetDateTime.of(LocalDate.of(1970, 1, 2), LocalTime.of(0, 0, 0, 0), ZoneOffset.UTC);
    assertEquals(dt.toEpochSecond(), 24L * 60L * 60L);
}
Also used : OffsetDateTime(java.time.OffsetDateTime)

Example 90 with OffsetDateTime

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

the class TestOffsetDateTime_instants method factory_ofInstant_allDaysInCycle.

public void factory_ofInstant_allDaysInCycle() {
    // sanity check using different algorithm
    OffsetDateTime expected = OffsetDateTime.of(LocalDate.of(1970, 1, 1), LocalTime.of(0, 0, 0, 0), ZoneOffset.UTC);
    for (long i = 0; i < 146097; i++) {
        Instant instant = Instant.ofEpochSecond(i * 24L * 60L * 60L);
        OffsetDateTime test = OffsetDateTime.ofInstant(instant, ZoneOffset.UTC);
        assertEquals(test, expected);
        expected = expected.plusDays(1);
    }
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Instant(java.time.Instant)

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