Skip to content

Commit 02572c2

Browse files
authored
Fix DateTime with ZoneId unpacking (#1097)
The timezone offset was miss-calculated because of an error on extracting timezone information when the hour equals to `0`. The problems happens because `Intl.DateTimeFormat` when configured with `hour12: false` returns `0` hour as `24`. The solution for this is convert `24` to `0` before calculate the `offset`. NOTE: Other valid solution would be change `hourCycle` to `h23`. However, this solution is not supported by all javascript environment.
1 parent 5185237 commit 02572c2

File tree

7 files changed

+39
-0
lines changed

7 files changed

+39
-0
lines changed

packages/bolt-connection/src/bolt/bolt-protocol-v5x0.utc.transformer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ function getTimeInZoneId (timeZoneId, epochSecond, nano) {
185185
currentValue.value.toUpperCase() === 'B'
186186
? year => year.subtract(1).negate() // 1BC equals to year 0 in astronomical year numbering
187187
: identity
188+
} else if (currentValue.type === 'hour') {
189+
obj.hour = int(currentValue.value).modulo(24)
188190
} else if (currentValue.type !== 'literal') {
189191
obj[currentValue.type] = int(currentValue.value)
190192
}

packages/bolt-connection/test/bolt/bolt-protocol-v4x4.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,13 @@ describe('#unit BoltProtocolV4x4', () => {
10351035
1655212878, 183_000_000, 'Australia/Eucla'
10361036
]),
10371037
new DateTime(2022, 6, 14, 22, 6, 18, 183_000_000, 8 * 60 * 60 + 45 * 60, 'Australia/Eucla')
1038+
],
1039+
[
1040+
'DateTimeWithZoneId / Midnight',
1041+
new structure.Structure(0x69, [
1042+
1685397950, 183_000_000, 'Europe/Berlin'
1043+
]),
1044+
new DateTime(2023, 5, 30, 0, 5, 50, 183_000_000, 2 * 60 * 60, 'Europe/Berlin')
10381045
]
10391046
])('should unpack temporal types (%s)', (_, struct, object) => {
10401047
const packable = protocol.packable(struct)

packages/bolt-connection/test/bolt/bolt-protocol-v5x0.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,13 @@ describe('#unit BoltProtocolV5x0', () => {
10011001
1592231400, 183_000_000, 'Pacific/Honolulu'
10021002
]),
10031003
new DateTime(2020, 6, 15, 4, 30, 0, 183_000_000, -10 * 60 * 60, 'Pacific/Honolulu')
1004+
],
1005+
[
1006+
'DateTimeWithZoneId / Midnight',
1007+
new structure.Structure(0x69, [
1008+
1685397950, 183_000_000, 'Europe/Berlin'
1009+
]),
1010+
new DateTime(2023, 5, 30, 0, 5, 50, 183_000_000, 2 * 60 * 60, 'Europe/Berlin')
10041011
]
10051012
])('should unpack spatial types and temporal types (%s)', (_, struct, object) => {
10061013
const buffer = alloc(256)

packages/bolt-connection/test/bolt/bolt-protocol-v5x1.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,13 @@ describe('#unit BoltProtocolV5x1', () => {
10781078
1592231400, 183_000_000, 'Pacific/Honolulu'
10791079
]),
10801080
new DateTime(2020, 6, 15, 4, 30, 0, 183_000_000, -10 * 60 * 60, 'Pacific/Honolulu')
1081+
],
1082+
[
1083+
'DateTimeWithZoneId / Midnight',
1084+
new structure.Structure(0x69, [
1085+
1685397950, 183_000_000, 'Europe/Berlin'
1086+
]),
1087+
new DateTime(2023, 5, 30, 0, 5, 50, 183_000_000, 2 * 60 * 60, 'Europe/Berlin')
10811088
]
10821089
])('should unpack spatial types and temporal types (%s)', (_, struct, object) => {
10831090
const buffer = alloc(256)

packages/bolt-connection/test/bolt/bolt-protocol-v5x2.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,13 @@ describe('#unit BoltProtocolV5x2', () => {
10841084
1592231400, 183_000_000, 'Pacific/Honolulu'
10851085
]),
10861086
new DateTime(2020, 6, 15, 4, 30, 0, 183_000_000, -10 * 60 * 60, 'Pacific/Honolulu')
1087+
],
1088+
[
1089+
'DateTimeWithZoneId / Midnight',
1090+
new structure.Structure(0x69, [
1091+
1685397950, 183_000_000, 'Europe/Berlin'
1092+
]),
1093+
new DateTime(2023, 5, 30, 0, 5, 50, 183_000_000, 2 * 60 * 60, 'Europe/Berlin')
10871094
]
10881095
])('should unpack spatial types and temporal types (%s)', (_, struct, object) => {
10891096
const buffer = alloc(256)

packages/bolt-connection/test/bolt/bolt-protocol-v5x3.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,13 @@ describe('#unit BoltProtocolV5x3', () => {
10931093
1592231400, 183_000_000, 'Pacific/Honolulu'
10941094
]),
10951095
new DateTime(2020, 6, 15, 4, 30, 0, 183_000_000, -10 * 60 * 60, 'Pacific/Honolulu')
1096+
],
1097+
[
1098+
'DateTimeWithZoneId / Midnight',
1099+
new structure.Structure(0x69, [
1100+
1685397950, 183_000_000, 'Europe/Berlin'
1101+
]),
1102+
new DateTime(2023, 5, 30, 0, 5, 50, 183_000_000, 2 * 60 * 60, 'Europe/Berlin')
10961103
]
10971104
])('should unpack spatial types and temporal types (%s)', (_, struct, object) => {
10981105
const buffer = alloc(256)

packages/neo4j-driver-deno/lib/bolt-connection/bolt/bolt-protocol-v5x0.utc.transformer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ function getTimeInZoneId (timeZoneId, epochSecond, nano) {
185185
currentValue.value.toUpperCase() === 'B'
186186
? year => year.subtract(1).negate() // 1BC equals to year 0 in astronomical year numbering
187187
: identity
188+
} else if (currentValue.type === 'hour') {
189+
obj.hour = int(currentValue.value).modulo(24)
188190
} else if (currentValue.type !== 'literal') {
189191
obj[currentValue.type] = int(currentValue.value)
190192
}

0 commit comments

Comments
 (0)