@@ -159,25 +159,26 @@ private void packLocalDateTime( LocalDateTime localDateTime ) throws IOException
159159
160160 private void packZonedDateTime ( ZonedDateTime zonedDateTime ) throws IOException
161161 {
162- Instant instant = zonedDateTime .toInstant ( );
163- ZoneId zone = zonedDateTime .getZone ();
162+ long epochSecondLocal = zonedDateTime .toLocalDateTime (). toEpochSecond ( UTC );
163+ int nano = zonedDateTime .getNano ();
164164
165+ ZoneId zone = zonedDateTime .getZone ();
165166 if ( zone instanceof ZoneOffset )
166167 {
167168 int offsetSeconds = ((ZoneOffset ) zone ).getTotalSeconds ();
168169
169170 packer .packStructHeader ( DATE_TIME_STRUCT_SIZE , DATE_TIME_WITH_ZONE_OFFSET );
170- packer .pack ( instant . getEpochSecond () );
171- packer .pack ( instant . getNano () );
171+ packer .pack ( epochSecondLocal );
172+ packer .pack ( nano );
172173 packer .pack ( offsetSeconds );
173174 }
174175 else
175176 {
176177 String zoneId = zone .getId ();
177178
178179 packer .packStructHeader ( DATE_TIME_STRUCT_SIZE , DATE_TIME_WITH_ZONE_ID );
179- packer .pack ( instant . getEpochSecond () );
180- packer .pack ( instant . getNano () );
180+ packer .pack ( epochSecondLocal );
181+ packer .pack ( nano );
181182 packer .pack ( zoneId );
182183 }
183184 }
@@ -287,8 +288,8 @@ private Value unpackTime() throws IOException
287288
288289 private Value unpackLocalTime () throws IOException
289290 {
290- long nanoOfDay = unpacker .unpackLong ();
291- return value ( LocalTime .ofNanoOfDay ( nanoOfDay ) );
291+ long nanoOfDayLocal = unpacker .unpackLong ();
292+ return value ( LocalTime .ofNanoOfDay ( nanoOfDayLocal ) );
292293 }
293294
294295 private Value unpackLocalDateTime () throws IOException
@@ -300,24 +301,18 @@ private Value unpackLocalDateTime() throws IOException
300301
301302 private Value unpackDateTimeWithZoneOffset () throws IOException
302303 {
303- long epochSecondUtc = unpacker .unpackLong ();
304+ long epochSecondLocal = unpacker .unpackLong ();
304305 int nano = Math .toIntExact ( unpacker .unpackLong () );
305306 int offsetSeconds = Math .toIntExact ( unpacker .unpackLong () );
306-
307- Instant instant = Instant .ofEpochSecond ( epochSecondUtc , nano );
308- ZoneOffset zoneOffset = ZoneOffset .ofTotalSeconds ( offsetSeconds );
309- return value ( ZonedDateTime .ofInstant ( instant , zoneOffset ) );
307+ return value ( newZonedDateTime ( epochSecondLocal , nano , ZoneOffset .ofTotalSeconds ( offsetSeconds ) ) );
310308 }
311309
312310 private Value unpackDateTimeWithZoneId () throws IOException
313311 {
314- long epochSecondUtc = unpacker .unpackLong ();
312+ long epochSecondLocal = unpacker .unpackLong ();
315313 int nano = Math .toIntExact ( unpacker .unpackLong () );
316314 String zoneIdString = unpacker .unpackString ();
317-
318- Instant instant = Instant .ofEpochSecond ( epochSecondUtc , nano );
319- ZoneId zoneId = ZoneId .of ( zoneIdString );
320- return value ( ZonedDateTime .ofInstant ( instant , zoneId ) );
315+ return value ( newZonedDateTime ( epochSecondLocal , nano , ZoneId .of ( zoneIdString ) ) );
321316 }
322317
323318 private Value unpackDuration () throws IOException
@@ -345,5 +340,12 @@ private Value unpackPoint3D() throws IOException
345340 double z = unpacker .unpackDouble ();
346341 return point ( srid , x , y , z );
347342 }
343+
344+ private static ZonedDateTime newZonedDateTime ( long epochSecondLocal , long nano , ZoneId zoneId )
345+ {
346+ Instant instant = Instant .ofEpochSecond ( epochSecondLocal , nano );
347+ LocalDateTime localDateTime = LocalDateTime .ofInstant ( instant , UTC );
348+ return ZonedDateTime .of ( localDateTime , zoneId );
349+ }
348350 }
349351}
0 commit comments