Search in sources :

Example 76 with ZoneOffset

use of java.time.ZoneOffset in project j2objc by google.

the class TCKZoneOffset method test_factory_int_hours.

// -----------------------------------------------------------------------
@Test
public void test_factory_int_hours() {
    for (int i = -18; i <= 18; i++) {
        ZoneOffset test = ZoneOffset.ofHours(i);
        doTestOffset(test, i, 0, 0);
    }
}
Also used : ZoneOffset(java.time.ZoneOffset) Test(org.junit.Test)

Example 77 with ZoneOffset

use of java.time.ZoneOffset in project j2objc by google.

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.junit.Test)

Example 78 with ZoneOffset

use of java.time.ZoneOffset in project j2objc by google.

the class TCKZoneOffset method test_getRules.

// -----------------------------------------------------------------------
// getRules()
// -----------------------------------------------------------------------
@Test
public void test_getRules() {
    ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(1, 2, 3);
    assertEquals(offset.getRules().isFixedOffset(), true);
    assertEquals(offset.getRules().getOffset((Instant) null), offset);
    assertEquals(offset.getRules().getDaylightSavings((Instant) null), Duration.ZERO);
    assertEquals(offset.getRules().getStandardOffset((Instant) null), offset);
    assertEquals(offset.getRules().nextTransition((Instant) null), null);
    assertEquals(offset.getRules().previousTransition((Instant) null), null);
    assertEquals(offset.getRules().isValidOffset((LocalDateTime) null, offset), true);
    assertEquals(offset.getRules().isValidOffset((LocalDateTime) null, ZoneOffset.UTC), false);
    assertEquals(offset.getRules().isValidOffset((LocalDateTime) null, null), false);
    assertEquals(offset.getRules().getOffset((LocalDateTime) null), offset);
    assertEquals(offset.getRules().getValidOffsets((LocalDateTime) null), Arrays.asList(offset));
    assertEquals(offset.getRules().getTransition((LocalDateTime) null), null);
    assertEquals(offset.getRules().getTransitions().size(), 0);
    assertEquals(offset.getRules().getTransitionRules().size(), 0);
}
Also used : LocalDateTime(java.time.LocalDateTime) Instant(java.time.Instant) ZoneOffset(java.time.ZoneOffset) Test(org.junit.Test)

Example 79 with ZoneOffset

use of java.time.ZoneOffset in project j2objc by google.

the class TCKZoneOffset method test_factory_string_hours_minutes_seconds_colon.

@Test
public void test_factory_string_hours_minutes_seconds_colon() {
    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("-18:00:00");
    doTestOffset(test1, -18, 0, 0);
    ZoneOffset test2 = ZoneOffset.of("+18:00:00");
    doTestOffset(test2, 18, 0, 0);
}
Also used : ZoneOffset(java.time.ZoneOffset) Test(org.junit.Test)

Example 80 with ZoneOffset

use of java.time.ZoneOffset in project j2objc by google.

the class TCKZonedDateTime method now_Clock_offsets.

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

Aggregations

ZoneOffset (java.time.ZoneOffset)201 Test (org.junit.Test)51 LocalDateTime (java.time.LocalDateTime)36 ZoneId (java.time.ZoneId)36 Test (org.testng.annotations.Test)35 ZonedDateTime (java.time.ZonedDateTime)27 LocalTime (java.time.LocalTime)25 ZoneRules (java.time.zone.ZoneRules)23 OffsetDateTime (java.time.OffsetDateTime)20 Instant (java.time.Instant)17 LocalDate (java.time.LocalDate)16 TemporalAccessor (java.time.temporal.TemporalAccessor)11 ZoneOffsetTransition (java.time.zone.ZoneOffsetTransition)11 OffsetTime (java.time.OffsetTime)10 DateTimeFormatter (java.time.format.DateTimeFormatter)10 ArrayList (java.util.ArrayList)8 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)7 List (java.util.List)6 BigDecimal (java.math.BigDecimal)5 Clock (java.time.Clock)5