Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DateTime with ZoneId for years between 00-99 #992 #991

Merged
merged 3 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions packages/bolt-connection/src/packstream/packstream-utc.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,10 @@ export function packDateTime (value, packer) {
era: 'narrow'
})

const l = epochSecondAndNanoToLocalDateTime(epochSecond, nano)
const utc = Date.UTC(
int(l.year).toNumber(),
int(l.month).toNumber() - 1,
int(l.day).toNumber(),
int(l.hour).toNumber(),
int(l.minute).toNumber(),
int(l.second).toNumber()
)
const utc = int(epochSecond)
.multiply(1000)
.add(int(nano).div(1_000_000))
.toNumber()

const formattedUtcParts = formatter.formatToParts(utc)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ describe('#unit PackStreamV2', () => {
[
'DateWithWithZoneId / Min Date',
new DateTime(-99_999, 12, 31, 23, 59, 59, 999_999_999, undefined, 'Pacific/Samoa')
],
[
'DateWithWithZoneId / Ambiguous date between 00 and 99',
new DateTime(50, 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})
Expand Down
39 changes: 37 additions & 2 deletions packages/neo4j-driver/test/temporal-types.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,24 @@ describe('#integration temporal-types', () => {
expect(records.length).toEqual(1)

const value = records[0].get(0)
expect(value).toEqual(expectedValue)

if (
expectedValue.timeZoneId != null &&
value.timeZoneOffsetSeconds != null &&
neo4j.isDateTime(value) &&
neo4j.isDateTime(expectedValue)) {
expect(value).toEqual(jasmine.objectContaining({
year: expectedValue.year,
month: expectedValue.month,
day: expectedValue.day,
hour: expectedValue.hour,
second: expectedValue.second,
nanosecond: expectedValue.nanosecond,
timeZoneId: expectedValue.timeZoneId
}))
} else {
expect(value).toEqual(expectedValue)
}
} finally {
await session.close()
}
Expand All @@ -1457,7 +1474,25 @@ describe('#integration temporal-types', () => {
expect(records.length).toEqual(1)

const receivedValue = records[0].get(0)
expect(receivedValue).toEqual(value)
// Amend test to ignore timeZoneOffsetInSeconds returned by the
// new servers in ZonedDateTime with the utc fix
if (
value.timeZoneId != null &&
receivedValue.timeZoneOffsetSeconds != null &&
neo4j.isDateTime(value) &&
neo4j.isDateTime(receivedValue)) {
expect(receivedValue).toEqual(jasmine.objectContaining({
year: value.year,
month: value.month,
day: value.day,
hour: value.hour,
second: value.second,
nanosecond: value.nanosecond,
timeZoneId: value.timeZoneId
}))
} else {
expect(receivedValue).toEqual(value)
}
}

async function testDurationToString (values) {
Expand Down