Datetime function timezone issue
LucasBoberg opened this issue · 2 comments
Bug Report
The datetime() function returns the wrong timezone in node and Chrome but no in Firefox and bun.
Reproduce
Using the following query
RETURN datetime('2023-05-30T01:00:00[America/New_York]')
On Chrome and node I get the following, which is wrong
DateTime {
year: Integer { low: 2023, high: 0 },
month: Integer { low: 5, high: 0 },
day: Integer { low: 30, high: 0 },
hour: Integer { low: 0, high: 0 },
minute: Integer { low: 59, high: 0 },
second: Integer { low: 0, high: 0 },
nanosecond: Integer { low: 0, high: 0 },
timeZoneOffsetSeconds: Integer { low: 72000, high: 0 },
timeZoneId: 'America/New_York'
}
On Firefox and bun I get the following, which is correct
DateTime {
year: Integer { low: 2023, high: 0 },
month: Integer { low: 5, high: 0 },
day: Integer { low: 30, high: 0 },
hour: Integer { low: 0, high: 0 },
minute: Integer { low: 59, high: 0 },
second: Integer { low: 0, high: 0 },
nanosecond: Integer { low: 0, high: 0 },
timeZoneOffsetSeconds: Integer { low: -14400, high: -1 },
timeZoneId: 'America/New_York'
}
The difference is the timeZoneOffsetSeconds which is for some reason different and wrong on Chrome and node
Code for node
const neo4j = require('neo4j-driver')
const driver = neo4j.driver("neo4j://localhost:7687", neo4j.auth.basic("neo4j", "password"))
const session = driver.session()
async function run() {
try {
const result = await session.run(
"RETURN datetime('2023-05-30T00:59:00[America/New_York]')"
)
const singleRecord = result.records[0]
const node = singleRecord.get(0)
console.log(node)
} finally {
await session.close()
}
// on application exit:
await driver.close()
}
run()
Code for bun
import neo4j from 'neo4j-driver'
const driver = neo4j.driver("neo4j://localhost:7687", neo4j.auth.basic("neo4j", "password"))
const session = driver.session()
async function run() {
try {
const result = await session.run(
"RETURN datetime('2023-05-30T00:59:00[America/New_York]')"
)
const singleRecord = result.records[0]
const node = singleRecord.get(0)
console.log(node)
} finally {
await session.close()
}
// on application exit:
await driver.close()
}
run()
My Environment
Javascript Runtime Version: node v20.3.0, bun 0.6.9, Firefox 114.0.1, Chrome 114
Driver Version: 5.9.1
Neo4j Version and Edition: Neo4j 5.3.0 enterprise
Operating System: macOS 10.13.4
Hey @LucasBoberg,
i've tried to reproduce the issue without success.
Could you check the result of this calls in your chrome and firefox?
const formatter = new Intl.DateTimeFormat('en-US', {
timeZone: 'America/New_York',
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
hour12: false,
era: 'narrow'
})
console.log(formatter.formatToParts(Date.now()))
When using this code:
const driver = neo4j.driver('neo4j://localhost:7687', neo4j.auth.basic('neo4j', 'password'))
driver.executeQuery("RETURN datetime('2023-05-30T01:00:00[America/New_York]') as dt")
.then(({ records: [record] }) => {
console.log('dt', record.get('dt'))
}).finally(async () => driver.close())
It works as expected but my code provided above does not work but still return a value just a wrong one.
The top one being the result from the code in this comment and the one on the bottom being the code provided in the issue.