Search in sources :

Example 51 with ZoneOffset

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

the class TCKZoneOffset method test_adjustInto_ZonedDateTime.

//-----------------------------------------------------------------------
// adjustInto()
//-----------------------------------------------------------------------
@Test
public void test_adjustInto_ZonedDateTime() {
    ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
    for (String zoneId : ZoneId.getAvailableZoneIds()) {
        //Do not change offset of ZonedDateTime after adjustInto()
        ZonedDateTime zonedDateTime_target = ZonedDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneId.of(zoneId));
        ZonedDateTime zonedDateTime_result = (ZonedDateTime) (base.adjustInto(zonedDateTime_target));
        assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());
        OffsetDateTime offsetDateTime_target = zonedDateTime_target.toOffsetDateTime();
        OffsetDateTime offsetDateTime_result = (OffsetDateTime) (base.adjustInto(offsetDateTime_target));
        assertEquals(base, offsetDateTime_result.getOffset());
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) OffsetDateTime(java.time.OffsetDateTime) ZoneOffset(java.time.ZoneOffset) Test(org.testng.annotations.Test)

Example 52 with ZoneOffset

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

the class TCKZoneOffset method test_factory_string_hours_minutes_seconds_noColon.

@Test
public void test_factory_string_hours_minutes_seconds_noColon() {
    for (int i = -17; i <= 17; i++) {
        for (int j = -59; j <= 59; j++) {
            for (int k = -59; k <= 59; k++) {
                if ((i < 0 && j <= 0 && k <= 0) || (i > 0 && j >= 0 && k >= 0) || (i == 0 && ((j < 0 && k <= 0) || (j > 0 && k >= 0) || j == 0))) {
                    String str = (i < 0 || j < 0 || k < 0 ? "-" : "+") + Integer.toString(Math.abs(i) + 100).substring(1) + Integer.toString(Math.abs(j) + 100).substring(1) + Integer.toString(Math.abs(k) + 100).substring(1);
                    ZoneOffset test = ZoneOffset.of(str);
                    doTestOffset(test, i, j, k);
                }
            }
        }
    }
    ZoneOffset test1 = ZoneOffset.of("-180000");
    doTestOffset(test1, -18, 0, 0);
    ZoneOffset test2 = ZoneOffset.of("+180000");
    doTestOffset(test2, 18, 0, 0);
}
Also used : ZoneOffset(java.time.ZoneOffset) Test(org.testng.annotations.Test)

Example 53 with ZoneOffset

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

the class TCKZoneOffset method test_getTotalSeconds.

//-----------------------------------------------------------------------
// getTotalSeconds()
//-----------------------------------------------------------------------
@Test
public void test_getTotalSeconds() {
    ZoneOffset offset = ZoneOffset.ofTotalSeconds(60 * 60 + 1);
    assertEquals(offset.getTotalSeconds(), 60 * 60 + 1);
}
Also used : ZoneOffset(java.time.ZoneOffset) Test(org.testng.annotations.Test)

Example 54 with ZoneOffset

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

the class TCKZoneOffset method test_factory_string_hours.

@Test
public void test_factory_string_hours() {
    for (int i = -18; i <= 18; i++) {
        String str = (i < 0 ? "-" : "+") + Integer.toString(Math.abs(i) + 100).substring(1);
        ZoneOffset test = ZoneOffset.of(str);
        doTestOffset(test, i, 0, 0);
    }
}
Also used : ZoneOffset(java.time.ZoneOffset) Test(org.testng.annotations.Test)

Example 55 with ZoneOffset

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

the class TCKZoneId method factory_from_TemporalAccessor_offset.

@Test
public void factory_from_TemporalAccessor_offset() {
    ZoneOffset offset = ZoneOffset.ofHours(1);
    assertEquals(ZoneId.from(offset), offset);
}
Also used : ZoneOffset(java.time.ZoneOffset) Test(org.testng.annotations.Test)

Aggregations

ZoneOffset (java.time.ZoneOffset)64 Test (org.testng.annotations.Test)35 LocalDateTime (java.time.LocalDateTime)10 ZoneId (java.time.ZoneId)10 ZoneRules (java.time.zone.ZoneRules)9 ZonedDateTime (java.time.ZonedDateTime)8 Instant (java.time.Instant)6 OffsetDateTime (java.time.OffsetDateTime)5 DateTimeFormatter (java.time.format.DateTimeFormatter)5 ZoneOffsetTransition (java.time.zone.ZoneOffsetTransition)4 Clock (java.time.Clock)3 LocalTime (java.time.LocalTime)3 Duration (java.time.Duration)2 LocalDate (java.time.LocalDate)2 OffsetTime (java.time.OffsetTime)2 ChronoField (java.time.temporal.ChronoField)2 TemporalAccessor (java.time.temporal.TemporalAccessor)2 List (java.util.List)2 Cache (com.github.benmanes.caffeine.cache.Cache)1 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1