Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -33,14 +33,8 @@ exports[`#unit BoltProtocolV1 .packable() should pack types introduced afterward
{
"days": 1,
"months": 1,
"nanoseconds": Integer {
"high": 0,
"low": 1,
},
"seconds": Integer {
"high": 0,
"low": 1,
},
"nanoseconds": 1,
"seconds": 1,
}
`;

Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/integer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,13 @@ const inSafeRange = Integer.inSafeRange
*/
const toNumber = Integer.toNumber

/**
* Converts a variable to a BigInt
* @access public
* @param {Mixed} value - The variable to convert
* @return {BigInt} - the variable as a BigInt
*/
const toBigInt = Integer.valueOf
/**
* Converts the integer to a string representation
* @access public
Expand All @@ -1109,6 +1116,6 @@ const toNumber = Integer.toNumber
*/
const toString = Integer.toString

export { int, isInt, inSafeRange, toNumber, toString }
export { int, isInt, inSafeRange, toNumber, toBigInt, toString }

export default Integer
10 changes: 9 additions & 1 deletion packages/core/src/temporal-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
assertValidDate
} from './internal/util'
import { newError } from './error'
import Integer, { int, toNumber } from './integer'
import Integer, { int, toNumber, isInt } from './integer'

const IDENTIFIER_PROPERTY_ATTRIBUTES = {
value: true,
Expand Down Expand Up @@ -79,6 +79,14 @@ export class Duration<T extends NumberOrInteger = Integer> {
* @type {NumberOrInteger}
*/
this.nanoseconds = util.normalizeNanosecondsForDuration(nanoseconds) as T
if (typeof this.months === 'number' && isInt(this.nanoseconds) && isInt(this.seconds)) {
this.seconds = this.seconds.toNumber() as T
this.nanoseconds = this.nanoseconds.toNumber() as T
}
if (typeof this.months === 'bigint' && isInt(this.nanoseconds) && isInt(this.seconds)) {
this.seconds = this.seconds.toBigInt() as T
this.nanoseconds = this.nanoseconds.toBigInt() as T
}
Object.freeze(this)
}

Expand Down
6 changes: 3 additions & 3 deletions packages/core/test/__snapshots__/json.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ exports[`json .stringify should handle DateTime in list 1`] = `"[{"year":2024,"m

exports[`json .stringify should handle DateTime in object 1`] = `"{"key":{"year":2024,"month":6,"day":13,"hour":10,"minute":0,"second":30,"nanosecond":134,"timeZoneOffsetSeconds":-3600,"timeZoneId":"Europe/Berlin"}}"`;

exports[`json .stringify should handle Duration 1`] = `"{"months":10,"days":2,"seconds":{"low":35,"high":0},"nanoseconds":{"low":100,"high":0}}"`;
exports[`json .stringify should handle Duration 1`] = `"{"months":10,"days":2,"seconds":35,"nanoseconds":100}"`;

exports[`json .stringify should handle Duration in list 1`] = `"[{"months":10,"days":2,"seconds":{"low":35,"high":0},"nanoseconds":{"low":100,"high":0}}]"`;
exports[`json .stringify should handle Duration in list 1`] = `"[{"months":10,"days":2,"seconds":35,"nanoseconds":100}]"`;

exports[`json .stringify should handle Duration in object 1`] = `"{"key":{"months":10,"days":2,"seconds":{"low":35,"high":0},"nanoseconds":{"low":100,"high":0}}}"`;
exports[`json .stringify should handle Duration in object 1`] = `"{"key":{"months":10,"days":2,"seconds":35,"nanoseconds":100}}"`;

exports[`json .stringify should handle Integer 1`] = `"{"low":5,"high":0}"`;

Expand Down
9 changes: 8 additions & 1 deletion packages/neo4j-driver-deno/lib/core/integer.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion packages/neo4j-driver-deno/lib/core/temporal-types.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/neo4j-driver/test/examples.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1101,8 +1101,8 @@ describe('#integration examples', () => {
expect(neo4j.isDuration(durationField)).toEqual(true)
expect(durationField.months.toInt()).toEqual(duration.months)
expect(durationField.days.toInt()).toEqual(duration.days)
expect(durationField.seconds).toEqual(duration.seconds)
expect(durationField.nanoseconds).toEqual(duration.nanoseconds)
expect(durationField.seconds.toInt()).toEqual(duration.seconds)
expect(durationField.nanoseconds.toInt()).toEqual(duration.nanoseconds)
} finally {
await session.close()
}
Expand Down