diff --git a/packages/bolt-connection/src/packstream/packstream-utc.js b/packages/bolt-connection/src/packstream/packstream-utc.js index 377ff95a2..50fcf6647 100644 --- a/packages/bolt-connection/src/packstream/packstream-utc.js +++ b/packages/bolt-connection/src/packstream/packstream-utc.js @@ -262,7 +262,8 @@ export function packDateTime (value, packer) { hour: 'numeric', minute: 'numeric', second: 'numeric', - hour12: false + hour12: false, + era: 'narrow' }) const l = epochSecondAndNanoToLocalDateTime(epochSecond, nano) @@ -278,12 +279,19 @@ export function packDateTime (value, packer) { const formattedUtcParts = formatter.formatToParts(utc) const localDateTime = formattedUtcParts.reduce((obj, currentValue) => { - if (currentValue.type !== 'literal') { + if (currentValue.type === 'era') { + obj.adjustEra = + currentValue.value.toLocaleUpperCase() === 'B' + ? year => year.subtract(1).negate() // 1BC equals to year 0 in astronomical year numbering + : year => year + } else if (currentValue.type !== 'literal') { obj[currentValue.type] = int(currentValue.value) } return obj }, {}) + localDateTime.year = localDateTime.adjustEra(localDateTime.year) + const epochInTimeZone = localDateTimeToEpochSecond( localDateTime.year, localDateTime.month, diff --git a/packages/bolt-connection/test/packstream/packstream-v2.test.js b/packages/bolt-connection/test/packstream/packstream-v2.test.js index 28e600646..223f142a6 100644 --- a/packages/bolt-connection/test/packstream/packstream-v2.test.js +++ b/packages/bolt-connection/test/packstream/packstream-v2.test.js @@ -276,6 +276,18 @@ describe('#unit PackStreamV2', () => { [ 'DateTimeWithZoneId / Sao Paulo just 1 after turn winter time', new DateTime(2019, 2, 18, 1, 0, 0, 183_000_000, undefined, 'America/Sao_Paulo') + ], + [ + 'DateWithWithZoneId / Berlin before common era', + new DateTime(-2020, 6, 15, 4, 30, 0, 183_000_000, undefined, 'Europe/Berlin') + ], + [ + 'DateWithWithZoneId / Max Date', + new DateTime(99_999, 12, 31, 23, 59, 59, 999_999_999, undefined, 'Pacific/Kiritimati') + ], + [ + 'DateWithWithZoneId / Min Date', + new DateTime(-99_999, 12, 31, 23, 59, 59, 999_999_999, undefined, 'Pacific/Samoa') ] ])('should pack and unpack DateTimeWithZoneId and without offset (%s)', (_, object) => { const unpacked = packAndUnpack(object, { disableLosslessIntegers: true, useUtc: true}) diff --git a/packages/neo4j-driver/test/temporal-types.test.js b/packages/neo4j-driver/test/temporal-types.test.js index cc74708d1..2146c72e3 100644 --- a/packages/neo4j-driver/test/temporal-types.test.js +++ b/packages/neo4j-driver/test/temporal-types.test.js @@ -39,7 +39,7 @@ const MAX_TEMPORAL_ARRAY_LENGTH = 1000 */ const MAX_DURATION_COMPONENT = 3000000000000 const MAX_NANO_OF_SECOND = 999999999 -const MAX_YEAR = 999999999 +const MAX_YEAR = 99_999 const MIN_YEAR = -MAX_YEAR const MAX_TIME_ZONE_OFFSET = 64800 const MIN_TIME_ZONE_OFFSET = -MAX_TIME_ZONE_OFFSET