Skip to content

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

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

Merged
merged 4 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,17 @@ function getTimeInZoneId (timeZoneId, epochSecond, nano) {
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)

const localDateTime = formattedUtcParts.reduce((obj, currentValue) => {
if (currentValue.type === 'era') {
obj.adjustEra =
currentValue.value.toLocaleUpperCase() === 'B'
currentValue.value.toUpperCase() === 'B'
? year => year.subtract(1).negate() // 1BC equals to year 0 in astronomical year numbering
: identity
} else if (currentValue.type !== 'literal') {
Expand Down
4 changes: 4 additions & 0 deletions packages/bolt-connection/test/bolt/bolt-protocol-v4x3.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,10 @@ describe('#unit BoltProtocolV4x3', () => {
[
'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 packable = protocol.packable(object)
Expand Down
4 changes: 4 additions & 0 deletions packages/bolt-connection/test/bolt/bolt-protocol-v4x4.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,10 @@ describe('#unit BoltProtocolV4x4', () => {
[
'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 packable = protocol.packable(object)
Expand Down
4 changes: 4 additions & 0 deletions packages/bolt-connection/test/bolt/bolt-protocol-v5x0.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,10 @@ describe('#unit BoltProtocolV5x0', () => {
[
'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 buffer = alloc(256)
Expand Down
2 changes: 1 addition & 1 deletion packages/neo4j-driver/test/examples.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ describe('#integration examples', () => {
it('service unavailable example', done => {
const console = consoleOverride
const consoleLoggedMsg = consoleOverridePromise
const uri = `bolt://${sharedNeo4j.hostname}:7688` // wrong port
const uri = `bolt://${sharedNeo4j.hostname}:7686` // wrong port
const password = 'wrongPassword'

// tag::service-unavailable[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ const LOCKS_TERMINATED_ERROR =
'Neo.TransientError.Transaction.LockClientStopped'
const OOM_ERROR = 'Neo.DatabaseError.General.OutOfMemoryError'

// Not exactly integration tests but annoyingly slow for being a unit tests.
describe('#integration TransactionExecutor', () => {
describe('#unit TransactionExecutor', () => {
it('should retry until database error happens', async () => {
await testNoRetryOnUnknownError(
[
Expand Down
38 changes: 34 additions & 4 deletions packages/neo4j-driver/test/temporal-types.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,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,10 +1474,23 @@ describe('#integration temporal-types', () => {
const receivedValue = records[0].get(0)
// Amend test to ignore timeZoneOffsetInSeconds returned by the
// new servers in ZonedDateTime with the utc fix
if (value.timeZoneId != null && receivedValue.timeZoneOffsetSeconds != null) {
receivedValue.timeZoneOffsetInSeconds = undefined
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)
}
expect(receivedValue).toEqual(value)
}

async function testDurationToString (values) {
Expand Down