1919
2020import * as v1 from './packstream-v1' ;
2121import { isPoint , Point } from '../spatial-types' ;
22- import {
23- Date ,
24- DateTimeWithZoneId ,
25- DateTimeWithZoneOffset ,
26- Duration ,
27- isDate ,
28- isDateTimeWithZoneId ,
29- isDateTimeWithZoneOffset ,
30- isDuration ,
31- isLocalDateTime ,
32- isLocalTime ,
33- isTime ,
34- Time
35- } from '../temporal-types' ;
22+ import { Date , DateTime , Duration , isDate , isDateTime , isDuration , isLocalDateTime , isLocalTime , isTime , Time } from '../temporal-types' ;
3623import { int , isInt } from '../integer' ;
3724import {
3825 dateToEpochDay ,
@@ -97,10 +84,8 @@ export class Packer extends v1.Packer {
9784 return ( ) => packDate ( obj , this , onError ) ;
9885 } else if ( isLocalDateTime ( obj ) ) {
9986 return ( ) => packLocalDateTime ( obj , this , onError ) ;
100- } else if ( isDateTimeWithZoneOffset ( obj ) ) {
101- return ( ) => packDateTimeWithZoneOffset ( obj , this , onError ) ;
102- } else if ( isDateTimeWithZoneId ( obj ) ) {
103- return ( ) => packDateTimeWithZoneId ( obj , this , onError ) ;
87+ } else if ( isDateTime ( obj ) ) {
88+ return ( ) => packDateTime ( obj , this , onError ) ;
10489 } else {
10590 return super . packable ( obj , onError ) ;
10691 }
@@ -303,7 +288,7 @@ function unpackLocalTime(unpacker, structSize, buffer, disableLosslessIntegers)
303288 */
304289function packTime ( value , packer , onError ) {
305290 const nanoOfDay = localTimeToNanoOfDay ( value . hour , value . minute , value . second , value . nanosecond ) ;
306- const offsetSeconds = int ( value . offsetSeconds ) ;
291+ const offsetSeconds = int ( value . timeZoneOffsetSeconds ) ;
307292
308293 const packableStructFields = [
309294 packer . packable ( nanoOfDay , onError ) ,
@@ -396,21 +381,35 @@ function unpackLocalDateTime(unpacker, structSize, buffer, disableLosslessIntege
396381 return convertIntegerPropsIfNeeded ( result , disableLosslessIntegers ) ;
397382}
398383
384+ /**
385+ * Pack given date time.
386+ * @param {DateTime } value the date time value to pack.
387+ * @param {Packer } packer the packer to use.
388+ * @param {function } onError the error callback.
389+ */
390+ function packDateTime ( value , packer , onError ) {
391+ if ( value . timeZoneId ) {
392+ packDateTimeWithZoneId ( value , packer , onError ) ;
393+ } else {
394+ packDateTimeWithZoneOffset ( value , packer , onError ) ;
395+ }
396+ }
397+
399398/**
400399 * Pack given date time with zone offset.
401- * @param {DateTimeWithZoneOffset } value the date time value to pack.
400+ * @param {DateTime } value the date time value to pack.
402401 * @param {Packer } packer the packer to use.
403402 * @param {function } onError the error callback.
404403 */
405404function packDateTimeWithZoneOffset ( value , packer , onError ) {
406405 const epochSecond = localDateTimeToEpochSecond ( value . year , value . month , value . day , value . hour , value . minute , value . second , value . nanosecond ) ;
407406 const nano = int ( value . nanosecond ) ;
408- const offsetSeconds = int ( value . offsetSeconds ) ;
407+ const timeZoneOffsetSeconds = int ( value . timeZoneOffsetSeconds ) ;
409408
410409 const packableStructFields = [
411410 packer . packable ( epochSecond , onError ) ,
412411 packer . packable ( nano , onError ) ,
413- packer . packable ( offsetSeconds , onError )
412+ packer . packable ( timeZoneOffsetSeconds , onError )
414413 ] ;
415414 packer . packStruct ( DATE_TIME_WITH_ZONE_OFFSET , packableStructFields , onError ) ;
416415}
@@ -421,36 +420,36 @@ function packDateTimeWithZoneOffset(value, packer, onError) {
421420 * @param {number } structSize the retrieved struct size.
422421 * @param {BaseBuffer } buffer the buffer to unpack from.
423422 * @param {boolean } disableLosslessIntegers if integer properties in the result date-time should be native JS numbers.
424- * @return {DateTimeWithZoneOffset } the unpacked date time with zone offset value.
423+ * @return {DateTime } the unpacked date time with zone offset value.
425424 */
426425function unpackDateTimeWithZoneOffset ( unpacker , structSize , buffer , disableLosslessIntegers ) {
427426 unpacker . _verifyStructSize ( 'DateTimeWithZoneOffset' , DATE_TIME_WITH_ZONE_OFFSET_STRUCT_SIZE , structSize ) ;
428427
429428 const epochSecond = unpacker . unpackInteger ( buffer ) ;
430429 const nano = unpacker . unpackInteger ( buffer ) ;
431- const offsetSeconds = unpacker . unpackInteger ( buffer ) ;
430+ const timeZoneOffsetSeconds = unpacker . unpackInteger ( buffer ) ;
432431
433432 const localDateTime = epochSecondAndNanoToLocalDateTime ( epochSecond , nano ) ;
434- const result = new DateTimeWithZoneOffset ( localDateTime . year , localDateTime . month , localDateTime . day ,
435- localDateTime . hour , localDateTime . minute , localDateTime . second , localDateTime . nanosecond , offsetSeconds ) ;
433+ const result = new DateTime ( localDateTime . year , localDateTime . month , localDateTime . day ,
434+ localDateTime . hour , localDateTime . minute , localDateTime . second , localDateTime . nanosecond , timeZoneOffsetSeconds , null ) ;
436435 return convertIntegerPropsIfNeeded ( result , disableLosslessIntegers ) ;
437436}
438437
439438/**
440439 * Pack given date time with zone id.
441- * @param {DateTimeWithZoneId } value the date time value to pack.
440+ * @param {DateTime } value the date time value to pack.
442441 * @param {Packer } packer the packer to use.
443442 * @param {function } onError the error callback.
444443 */
445444function packDateTimeWithZoneId ( value , packer , onError ) {
446445 const epochSecond = localDateTimeToEpochSecond ( value . year , value . month , value . day , value . hour , value . minute , value . second , value . nanosecond ) ;
447446 const nano = int ( value . nanosecond ) ;
448- const zoneId = value . zoneId ;
447+ const timeZoneId = value . timeZoneId ;
449448
450449 const packableStructFields = [
451450 packer . packable ( epochSecond , onError ) ,
452451 packer . packable ( nano , onError ) ,
453- packer . packable ( zoneId , onError )
452+ packer . packable ( timeZoneId , onError )
454453 ] ;
455454 packer . packStruct ( DATE_TIME_WITH_ZONE_ID , packableStructFields , onError ) ;
456455}
@@ -461,18 +460,18 @@ function packDateTimeWithZoneId(value, packer, onError) {
461460 * @param {number } structSize the retrieved struct size.
462461 * @param {BaseBuffer } buffer the buffer to unpack from.
463462 * @param {boolean } disableLosslessIntegers if integer properties in the result date-time should be native JS numbers.
464- * @return {DateTimeWithZoneId } the unpacked date time with zone id value.
463+ * @return {DateTime } the unpacked date time with zone id value.
465464 */
466465function unpackDateTimeWithZoneId ( unpacker , structSize , buffer , disableLosslessIntegers ) {
467466 unpacker . _verifyStructSize ( 'DateTimeWithZoneId' , DATE_TIME_WITH_ZONE_ID_STRUCT_SIZE , structSize ) ;
468467
469468 const epochSecond = unpacker . unpackInteger ( buffer ) ;
470469 const nano = unpacker . unpackInteger ( buffer ) ;
471- const zoneId = unpacker . unpack ( buffer ) ;
470+ const timeZoneId = unpacker . unpack ( buffer ) ;
472471
473472 const localDateTime = epochSecondAndNanoToLocalDateTime ( epochSecond , nano ) ;
474- const result = new DateTimeWithZoneId ( localDateTime . year , localDateTime . month , localDateTime . day ,
475- localDateTime . hour , localDateTime . minute , localDateTime . second , localDateTime . nanosecond , zoneId ) ;
473+ const result = new DateTime ( localDateTime . year , localDateTime . month , localDateTime . day ,
474+ localDateTime . hour , localDateTime . minute , localDateTime . second , localDateTime . nanosecond , null , timeZoneId ) ;
476475 return convertIntegerPropsIfNeeded ( result , disableLosslessIntegers ) ;
477476}
478477
0 commit comments