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);
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations