Skip to content

Commit 7d3f92e

Browse files
committed
Fix DateTime with ZoneId for years between 00-99
The error was happening because Date.UTC factory doesn't treats dates between 00-99 as 1900-1999. Removing the usage of this factory makes the code slighty faster while resolves the issue.
1 parent 4455a7f commit 7d3f92e

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

packages/bolt-connection/src/packstream/packstream-utc.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,10 @@ export function packDateTime (value, packer) {
266266
era: 'narrow'
267267
})
268268

269-
const l = epochSecondAndNanoToLocalDateTime(epochSecond, nano)
270-
const utc = Date.UTC(
271-
int(l.year).toNumber(),
272-
int(l.month).toNumber() - 1,
273-
int(l.day).toNumber(),
274-
int(l.hour).toNumber(),
275-
int(l.minute).toNumber(),
276-
int(l.second).toNumber()
277-
)
269+
const utc = int(epochSecond)
270+
.multiply(1000)
271+
.add(int(nano).div(1_000_000))
272+
.toNumber()
278273

279274
const formattedUtcParts = formatter.formatToParts(utc)
280275

packages/bolt-connection/test/packstream/packstream-v2.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ describe('#unit PackStreamV2', () => {
288288
[
289289
'DateWithWithZoneId / Min Date',
290290
new DateTime(-99_999, 12, 31, 23, 59, 59, 999_999_999, undefined, 'Pacific/Samoa')
291+
],
292+
[
293+
'DateWithWithZoneId / Ambiguous date between 00 and 99',
294+
new DateTime(50, 12, 31, 23, 59, 59, 999_999_999, undefined, 'Pacific/Samoa')
291295
]
292296
])('should pack and unpack DateTimeWithZoneId and without offset (%s)', (_, object) => {
293297
const unpacked = packAndUnpack(object, { disableLosslessIntegers: true, useUtc: true})

packages/neo4j-driver/test/temporal-types.test.js

+34-4
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,24 @@ describe('#integration temporal-types', () => {
14411441
expect(records.length).toEqual(1)
14421442

14431443
const value = records[0].get(0)
1444-
expect(value).toEqual(expectedValue)
1444+
1445+
if (
1446+
expectedValue.timeZoneId != null &&
1447+
value.timeZoneOffsetSeconds != null &&
1448+
neo4j.isDateTime(value) &&
1449+
neo4j.isDateTime(expectedValue)) {
1450+
expect(value).toEqual(jasmine.objectContaining({
1451+
year: expectedValue.year,
1452+
month: expectedValue.month,
1453+
day: expectedValue.day,
1454+
hour: expectedValue.hour,
1455+
second: expectedValue.second,
1456+
nanosecond: expectedValue.nanosecond,
1457+
timeZoneId: expectedValue.timeZoneId
1458+
}))
1459+
} else {
1460+
expect(value).toEqual(expectedValue)
1461+
}
14451462
} finally {
14461463
await session.close()
14471464
}
@@ -1459,10 +1476,23 @@ describe('#integration temporal-types', () => {
14591476
const receivedValue = records[0].get(0)
14601477
// Amend test to ignore timeZoneOffsetInSeconds returned by the
14611478
// new servers in ZonedDateTime with the utc fix
1462-
if (value.timeZoneId != null && receivedValue.timeZoneOffsetSeconds != null) {
1463-
receivedValue.timeZoneOffsetInSeconds = undefined
1479+
if (
1480+
value.timeZoneId != null &&
1481+
receivedValue.timeZoneOffsetSeconds != null &&
1482+
neo4j.isDateTime(value) &&
1483+
neo4j.isDateTime(receivedValue)) {
1484+
expect(receivedValue).toEqual(jasmine.objectContaining({
1485+
year: value.year,
1486+
month: value.month,
1487+
day: value.day,
1488+
hour: value.hour,
1489+
second: value.second,
1490+
nanosecond: value.nanosecond,
1491+
timeZoneId: value.timeZoneId
1492+
}))
1493+
} else {
1494+
expect(receivedValue).toEqual(value)
14641495
}
1465-
expect(receivedValue).toEqual(value)
14661496
}
14671497

14681498
async function testDurationToString (values) {

0 commit comments

Comments
 (0)