@@ -159,25 +159,26 @@ private void packLocalDateTime( LocalDateTime localDateTime ) throws IOException
159
159
160
160
private void packZonedDateTime ( ZonedDateTime zonedDateTime ) throws IOException
161
161
{
162
- Instant instant = zonedDateTime .toInstant ( );
163
- ZoneId zone = zonedDateTime .getZone ();
162
+ long epochSecondLocal = zonedDateTime .toLocalDateTime (). toEpochSecond ( UTC );
163
+ int nano = zonedDateTime .getNano ();
164
164
165
+ ZoneId zone = zonedDateTime .getZone ();
165
166
if ( zone instanceof ZoneOffset )
166
167
{
167
168
int offsetSeconds = ((ZoneOffset ) zone ).getTotalSeconds ();
168
169
169
170
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 );
172
173
packer .pack ( offsetSeconds );
173
174
}
174
175
else
175
176
{
176
177
String zoneId = zone .getId ();
177
178
178
179
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 );
181
182
packer .pack ( zoneId );
182
183
}
183
184
}
@@ -287,8 +288,8 @@ private Value unpackTime() throws IOException
287
288
288
289
private Value unpackLocalTime () throws IOException
289
290
{
290
- long nanoOfDay = unpacker .unpackLong ();
291
- return value ( LocalTime .ofNanoOfDay ( nanoOfDay ) );
291
+ long nanoOfDayLocal = unpacker .unpackLong ();
292
+ return value ( LocalTime .ofNanoOfDay ( nanoOfDayLocal ) );
292
293
}
293
294
294
295
private Value unpackLocalDateTime () throws IOException
@@ -300,24 +301,18 @@ private Value unpackLocalDateTime() throws IOException
300
301
301
302
private Value unpackDateTimeWithZoneOffset () throws IOException
302
303
{
303
- long epochSecondUtc = unpacker .unpackLong ();
304
+ long epochSecondLocal = unpacker .unpackLong ();
304
305
int nano = Math .toIntExact ( unpacker .unpackLong () );
305
306
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 ) ) );
310
308
}
311
309
312
310
private Value unpackDateTimeWithZoneId () throws IOException
313
311
{
314
- long epochSecondUtc = unpacker .unpackLong ();
312
+ long epochSecondLocal = unpacker .unpackLong ();
315
313
int nano = Math .toIntExact ( unpacker .unpackLong () );
316
314
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 ) ) );
321
316
}
322
317
323
318
private Value unpackDuration () throws IOException
@@ -345,5 +340,12 @@ private Value unpackPoint3D() throws IOException
345
340
double z = unpacker .unpackDouble ();
346
341
return point ( srid , x , y , z );
347
342
}
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
+ }
348
350
}
349
351
}
0 commit comments