@Override ZoneOffset getZoneOffset() { return value.getOffset(); }
@Override OffsetTime getTimePart( Supplier<ZoneId> defaultZone ) { ZoneOffset currentOffset = assertValidArgument( () -> ZonedDateTime.ofInstant( Instant.now(), defaultZone.get() ) ).getOffset(); return OffsetTime.of( value, currentOffset ); }
@Override OffsetTime getTimePart( Supplier<ZoneId> defaultZone ) { ZoneOffset currentOffset = assertValidArgument( () -> ZonedDateTime.ofInstant( Instant.now(), defaultZone.get() ) ).getOffset(); return OffsetTime.of(value.toLocalTime(), currentOffset); }
@Override OffsetTime getTimePart( Supplier<ZoneId> defaultZone ) { ZoneOffset offset = value.getOffset(); LocalTime localTime = value.toLocalTime(); return OffsetTime.of( localTime, offset ); }
@Override protected TimeValue selectTime( AnyValue temporal ) { if ( !(temporal instanceof TemporalValue) ) { throw new InvalidValuesArgumentException( String.format( "Cannot construct time from: %s", temporal ) ); } if ( temporal instanceof TimeValue && timezone == null ) { return (TimeValue) temporal; } TemporalValue v = (TemporalValue) temporal; OffsetTime time = v.getTimePart( defaultZone ); if ( timezone != null ) { ZoneOffset currentOffset = assertValidArgument( () -> ZonedDateTime.ofInstant( Instant.now(), timezone() ) ).getOffset(); time = time.withOffsetSameInstant( currentOffset ); } return time( time ); } };
if ( !(timezone instanceof ZoneOffset) ) timezone = assertValidArgument( () -> ZonedDateTime.ofInstant( Instant.now(), timezone() ) ).getOffset(); if ( timezone != null ) ZoneOffset currentOffset = assertValidArgument( () -> ZonedDateTime.ofInstant( Instant.now(), timezone() ) ).getOffset(); if ( selectingTime && selectingTimeZone )
ZoneOffset currentOffset = currentDT.getOffset(); truncatedOT = truncatedOT.withOffsetSameLocal( currentOffset );
private void assertTimestamp(String c4) { // '2014-09-08 17:51:04.777' // MySQL container is in UTC and the test time is during summer time period ZonedDateTime expectedTimestamp = ZonedDateTime.ofInstant( LocalDateTime.parse("2014-09-08T17:51:04.780").atZone(ZoneId.of("US/Samoa")).toInstant(), ZoneId.systemDefault()); ZoneId defaultZoneId = ZoneId.systemDefault(); ZonedDateTime c4DateTime = ZonedDateTime.parse(c4, ZonedTimestamp.FORMATTER).withZoneSameInstant(defaultZoneId); assertThat(c4DateTime.getYear()).isEqualTo(expectedTimestamp.getYear()); assertThat(c4DateTime.getMonth()).isEqualTo(expectedTimestamp.getMonth()); assertThat(c4DateTime.getDayOfMonth()).isEqualTo(expectedTimestamp.getDayOfMonth()); assertThat(c4DateTime.getHour()).isEqualTo(expectedTimestamp.getHour()); assertThat(c4DateTime.getMinute()).isEqualTo(expectedTimestamp.getMinute()); assertThat(c4DateTime.getSecond()).isEqualTo(expectedTimestamp.getSecond()); assertThat(c4DateTime.getNano()).isEqualTo(expectedTimestamp.getNano()); // We're running the connector in the same timezone as the server, so the timezone in the timestamp // should match our current offset ... LocalDateTime expectedLocalDateTime = LocalDateTime.parse("2014-09-08T17:51:04.780"); ZoneOffset expectedOffset = defaultZoneId.getRules().getOffset(expectedLocalDateTime); assertThat(c4DateTime.getOffset()).isEqualTo(expectedOffset); }
import java.time.ZoneId; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.format.TextStyle; import java.util.Locale; import java.util.Set; Set<String> zoneIds = ZoneId.getAvailableZoneIds(); for (String zoneId : zoneIds) { ZoneId zone = ZoneId.of(zoneId); ZonedDateTime zonedDateTime = ZonedDateTime.now(zone); ZoneOffset offset = zonedDateTime.getOffset(); String longName = zone.getDisplayName(TextStyle.FULL, Locale.ENGLISH); System.out.println("(" + offset + ") " + zoneId + ", " + longName); }
@Override protected ByteBuf writeValue(final ZonedDateTime value, final ByteBufAllocator allocator, final GraphBinaryWriter context) throws SerializationException { final CompositeByteBuf result = allocator.compositeBuffer(2); result.addComponent(true, context.writeValue(value.toLocalDateTime(), allocator, false)); result.addComponent(true, context.writeValue(value.getOffset(), allocator, false)); return result; } }
@Override ZoneOffset getZoneOffset() { return value.getOffset(); }
private Instant initCommitDateInstant(LocalDateTime commitDate, Instant commitDateInstant) { if (commitDateInstant != null) { return commitDateInstant; } //for old records without commitDateInstant return commitDate.toInstant(ZonedDateTime.now().getOffset()); }
/** * Get list of all time zone offsets supported. */ private static List<String> getAllTimeZones() { final List<String> lst = ZoneId.getAvailableZoneIds().stream() .map(id -> ZonedDateTime.now(ZoneId.of(id)).getOffset().getId().replace("Z", "+00:00")).distinct() .collect(Collectors.toList()); lst.sort(null); return lst; }
@Override OffsetTime getTimePart( Supplier<ZoneId> defaultZone ) { ZoneOffset currentOffset = assertValidArgument( () -> ZonedDateTime.ofInstant( Instant.now(), defaultZone.get() ) ).getOffset(); return OffsetTime.of( value, currentOffset ); }
/** Local (query engine) timezone including DST */ private static Duration localTimezoneDuration() { ZonedDateTime zdt = ZonedDateTime.now(); int tzDurationInSeconds = zdt.getOffset().getTotalSeconds(); Duration dur = NodeFunctions.duration(tzDurationInSeconds); return dur; }
@Override OffsetTime getTimePart( Supplier<ZoneId> defaultZone ) { ZoneOffset offset = value.getOffset(); LocalTime localTime = value.toLocalTime(); return OffsetTime.of( localTime, offset ); }
@Override protected TimeZone deserialize(String jsonValue, Unmarshaller unmarshaller, Type rtType) { try { final ZoneId zoneId = ZoneId.of(jsonValue); final ZonedDateTime zonedDateTime = LocalDateTime.now().atZone(zoneId); return new SimpleTimeZone(zonedDateTime.getOffset().getTotalSeconds() * 1000, zoneId.getId()); } catch (ZoneRulesException e) { throw new JsonbException(Messages.getMessage(MessageKeys.ZONE_PARSE_ERROR, jsonValue), e); } }
@Test void offsetShouldBeParsed() { ZonedDateTime dateTime = ZonedDateTime.parse("3 Jun 2017 04:35:11 -0712", ImapDateTimeFormatter.rfc5322()); assertThat(dateTime.getOffset()).isEqualTo(ZoneOffset.ofHoursMinutes(-7, -12)); }
@Override public ByteBuf writeValue(final ZonedDateTime value, final ByteBufAllocator allocator, final GraphBinaryWriter context) throws SerializationException { final CompositeByteBuf result = allocator.compositeBuffer(2); result.addComponent(true, context.writeValue(value.toLocalDateTime(), allocator, false)); result.addComponent(true, context.writeValue(value.getOffset(), allocator, false)); return result; } }