Search in sources :

Example 91 with ZoneOffset

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

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

Example 92 with ZoneOffset

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

the class TCKOffsetTime method now_Clock_offsets.

@Test
public void now_Clock_offsets() {
    Instant base = LocalDateTime.of(1970, 1, 1, 12, 0).toInstant(ZoneOffset.UTC);
    for (int i = -9; i < 15; i++) {
        ZoneOffset offset = ZoneOffset.ofHours(i);
        Clock clock = Clock.fixed(base, offset);
        OffsetTime test = OffsetTime.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 : OffsetTime(java.time.OffsetTime) Instant(java.time.Instant) Clock(java.time.Clock) ZoneOffset(java.time.ZoneOffset) Test(org.junit.Test)

Example 93 with ZoneOffset

use of java.time.ZoneOffset in project wildfly by wildfly.

the class AbstractTimeTestCase method testZoneOffset.

@Test
public void testZoneOffset() throws IOException {
    MarshallingTester<ZoneOffset> tester = this.factory.createTester();
    tester.test(ZoneOffset.MIN);
    tester.test(ZoneOffset.MAX);
    // Hawaii Standard Time
    tester.test(ZoneOffset.of("-10"));
    // New Zealand's Chatham Islands
    tester.test(ZoneOffset.of("+12:45"));
    Random random = new Random(System.currentTimeMillis());
    tester.test(ZoneOffset.ofHoursMinutesSeconds(random.nextInt(18), random.nextInt(60), random.nextInt(60)));
    tester.test(ZoneOffset.ofHoursMinutesSeconds(0 - random.nextInt(18), 0 - random.nextInt(60), 0 - random.nextInt(60)));
    tester.test(ZoneOffset.UTC);
}
Also used : Random(java.util.Random) ZoneOffset(java.time.ZoneOffset) Test(org.junit.Test)

Example 94 with ZoneOffset

use of java.time.ZoneOffset in project wildfly by wildfly.

the class ZonedDateTimeMarshaller method readFrom.

@Override
public ZonedDateTime readFrom(ProtoStreamReader reader) throws IOException {
    LocalDate date = LocalDateMarshaller.INSTANCE.getBuilder();
    LocalTime time = LocalTimeMarshaller.INSTANCE.getBuilder();
    ZoneId zone = ZoneOffsetMarshaller.INSTANCE.getBuilder();
    while (!reader.isAtEnd()) {
        int tag = reader.readTag();
        int index = WireType.getTagFieldNumber(tag);
        if (index >= DATE_INDEX && index < TIME_INDEX) {
            date = LocalDateMarshaller.INSTANCE.readField(reader, index - DATE_INDEX, date);
        } else if (index >= TIME_INDEX && index < OFFSET_INDEX) {
            time = LocalTimeMarshaller.INSTANCE.readField(reader, index - TIME_INDEX, time);
        } else if (index >= OFFSET_INDEX && index < ZONE_INDEX) {
            zone = ZoneOffsetMarshaller.INSTANCE.readField(reader, index - OFFSET_INDEX, (ZoneOffset) zone);
        } else if (index == ZONE_INDEX) {
            zone = ZoneId.of(reader.readString());
        } else {
            reader.skipField(tag);
        }
    }
    return ZonedDateTime.of(date, time, zone);
}
Also used : LocalTime(java.time.LocalTime) ZoneId(java.time.ZoneId) LocalDate(java.time.LocalDate) ZoneOffset(java.time.ZoneOffset)

Example 95 with ZoneOffset

use of java.time.ZoneOffset in project wildfly by wildfly.

the class OffsetTimeMarshaller method readFrom.

@Override
public OffsetTime readFrom(ProtoStreamReader reader) throws IOException {
    LocalTime time = LocalTimeMarshaller.INSTANCE.getBuilder();
    ZoneOffset offset = ZoneOffsetMarshaller.INSTANCE.getBuilder();
    while (!reader.isAtEnd()) {
        int tag = reader.readTag();
        int index = WireType.getTagFieldNumber(tag);
        if (index >= TIME_INDEX && index < OFFSET_INDEX) {
            time = LocalTimeMarshaller.INSTANCE.readField(reader, index - TIME_INDEX, time);
        } else if (index >= OFFSET_INDEX && index < OFFSET_INDEX + ZoneOffsetMarshaller.INSTANCE.getFields()) {
            offset = ZoneOffsetMarshaller.INSTANCE.readField(reader, index - OFFSET_INDEX, offset);
        } else {
            reader.skipField(tag);
        }
    }
    return OffsetTime.of(time, offset);
}
Also used : LocalTime(java.time.LocalTime) ZoneOffset(java.time.ZoneOffset)

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