diff --git a/src/v1/index.js b/src/v1/index.js index 8c4c53ace..ccdd08e3c 100644 --- a/src/v1/index.js +++ b/src/v1/index.js @@ -30,22 +30,7 @@ import {assertString, isEmptyObjectOrNull} from './internal/util'; import urlUtil from './internal/url-util'; import HttpDriver from './internal/http/http-driver'; import {isPoint, Point} from './spatial-types'; -import { - Date, - DateTimeWithZoneId, - DateTimeWithZoneOffset, - Duration, - isDate, - isDateTimeWithZoneId, - isDateTimeWithZoneOffset, - isDuration, - isLocalDateTime, - isLocalTime, - isTime, - LocalDateTime, - LocalTime, - Time -} from './temporal-types'; +import {Date, DateTime, Duration, isDate, isDateTime, isDuration, isLocalDateTime, isLocalTime, isTime, LocalDateTime, LocalTime, Time} from './temporal-types'; /** * @property {function(username: string, password: string, realm: ?string)} basic the function to create a @@ -225,8 +210,7 @@ const types = { Record, Point, Date, - DateTimeWithZoneId, - DateTimeWithZoneOffset, + DateTime, Duration, LocalDateTime, LocalTime, @@ -275,8 +259,7 @@ const forExport = { Point, isPoint, Date, - DateTimeWithZoneId, - DateTimeWithZoneOffset, + DateTime, Duration, LocalDateTime, LocalTime, @@ -286,8 +269,7 @@ const forExport = { isTime, isDate, isLocalDateTime, - isDateTimeWithZoneOffset, - isDateTimeWithZoneId + isDateTime }; export { @@ -303,8 +285,7 @@ export { Point, isPoint, Date, - DateTimeWithZoneId, - DateTimeWithZoneOffset, + DateTime, Duration, LocalDateTime, LocalTime, @@ -314,7 +295,6 @@ export { isTime, isDate, isLocalDateTime, - isDateTimeWithZoneOffset, - isDateTimeWithZoneId + isDateTime }; export default forExport; diff --git a/src/v1/internal/packstream-v2.js b/src/v1/internal/packstream-v2.js index af16eb0e6..370847e27 100644 --- a/src/v1/internal/packstream-v2.js +++ b/src/v1/internal/packstream-v2.js @@ -19,20 +19,7 @@ import * as v1 from './packstream-v1'; import {isPoint, Point} from '../spatial-types'; -import { - Date, - DateTimeWithZoneId, - DateTimeWithZoneOffset, - Duration, - isDate, - isDateTimeWithZoneId, - isDateTimeWithZoneOffset, - isDuration, - isLocalDateTime, - isLocalTime, - isTime, - Time -} from '../temporal-types'; +import {Date, DateTime, Duration, isDate, isDateTime, isDuration, isLocalDateTime, isLocalTime, isTime, Time} from '../temporal-types'; import {int, isInt} from '../integer'; import { dateToEpochDay, @@ -97,10 +84,8 @@ export class Packer extends v1.Packer { return () => packDate(obj, this, onError); } else if (isLocalDateTime(obj)) { return () => packLocalDateTime(obj, this, onError); - } else if (isDateTimeWithZoneOffset(obj)) { - return () => packDateTimeWithZoneOffset(obj, this, onError); - } else if (isDateTimeWithZoneId(obj)) { - return () => packDateTimeWithZoneId(obj, this, onError); + } else if (isDateTime(obj)) { + return () => packDateTime(obj, this, onError); } else { return super.packable(obj, onError); } @@ -303,7 +288,7 @@ function unpackLocalTime(unpacker, structSize, buffer, disableLosslessIntegers) */ function packTime(value, packer, onError) { const nanoOfDay = localTimeToNanoOfDay(value.hour, value.minute, value.second, value.nanosecond); - const offsetSeconds = int(value.offsetSeconds); + const offsetSeconds = int(value.timeZoneOffsetSeconds); const packableStructFields = [ packer.packable(nanoOfDay, onError), @@ -396,21 +381,35 @@ function unpackLocalDateTime(unpacker, structSize, buffer, disableLosslessIntege return convertIntegerPropsIfNeeded(result, disableLosslessIntegers); } +/** + * Pack given date time. + * @param {DateTime} value the date time value to pack. + * @param {Packer} packer the packer to use. + * @param {function} onError the error callback. + */ +function packDateTime(value, packer, onError) { + if (value.timeZoneId) { + packDateTimeWithZoneId(value, packer, onError); + } else { + packDateTimeWithZoneOffset(value, packer, onError); + } +} + /** * Pack given date time with zone offset. - * @param {DateTimeWithZoneOffset} value the date time value to pack. + * @param {DateTime} value the date time value to pack. * @param {Packer} packer the packer to use. * @param {function} onError the error callback. */ function packDateTimeWithZoneOffset(value, packer, onError) { const epochSecond = localDateTimeToEpochSecond(value.year, value.month, value.day, value.hour, value.minute, value.second, value.nanosecond); const nano = int(value.nanosecond); - const offsetSeconds = int(value.offsetSeconds); + const timeZoneOffsetSeconds = int(value.timeZoneOffsetSeconds); const packableStructFields = [ packer.packable(epochSecond, onError), packer.packable(nano, onError), - packer.packable(offsetSeconds, onError) + packer.packable(timeZoneOffsetSeconds, onError) ]; packer.packStruct(DATE_TIME_WITH_ZONE_OFFSET, packableStructFields, onError); } @@ -421,36 +420,36 @@ function packDateTimeWithZoneOffset(value, packer, onError) { * @param {number} structSize the retrieved struct size. * @param {BaseBuffer} buffer the buffer to unpack from. * @param {boolean} disableLosslessIntegers if integer properties in the result date-time should be native JS numbers. - * @return {DateTimeWithZoneOffset} the unpacked date time with zone offset value. + * @return {DateTime} the unpacked date time with zone offset value. */ function unpackDateTimeWithZoneOffset(unpacker, structSize, buffer, disableLosslessIntegers) { unpacker._verifyStructSize('DateTimeWithZoneOffset', DATE_TIME_WITH_ZONE_OFFSET_STRUCT_SIZE, structSize); const epochSecond = unpacker.unpackInteger(buffer); const nano = unpacker.unpackInteger(buffer); - const offsetSeconds = unpacker.unpackInteger(buffer); + const timeZoneOffsetSeconds = unpacker.unpackInteger(buffer); const localDateTime = epochSecondAndNanoToLocalDateTime(epochSecond, nano); - const result = new DateTimeWithZoneOffset(localDateTime.year, localDateTime.month, localDateTime.day, - localDateTime.hour, localDateTime.minute, localDateTime.second, localDateTime.nanosecond, offsetSeconds); + const result = new DateTime(localDateTime.year, localDateTime.month, localDateTime.day, + localDateTime.hour, localDateTime.minute, localDateTime.second, localDateTime.nanosecond, timeZoneOffsetSeconds, null); return convertIntegerPropsIfNeeded(result, disableLosslessIntegers); } /** * Pack given date time with zone id. - * @param {DateTimeWithZoneId} value the date time value to pack. + * @param {DateTime} value the date time value to pack. * @param {Packer} packer the packer to use. * @param {function} onError the error callback. */ function packDateTimeWithZoneId(value, packer, onError) { const epochSecond = localDateTimeToEpochSecond(value.year, value.month, value.day, value.hour, value.minute, value.second, value.nanosecond); const nano = int(value.nanosecond); - const zoneId = value.zoneId; + const timeZoneId = value.timeZoneId; const packableStructFields = [ packer.packable(epochSecond, onError), packer.packable(nano, onError), - packer.packable(zoneId, onError) + packer.packable(timeZoneId, onError) ]; packer.packStruct(DATE_TIME_WITH_ZONE_ID, packableStructFields, onError); } @@ -461,18 +460,18 @@ function packDateTimeWithZoneId(value, packer, onError) { * @param {number} structSize the retrieved struct size. * @param {BaseBuffer} buffer the buffer to unpack from. * @param {boolean} disableLosslessIntegers if integer properties in the result date-time should be native JS numbers. - * @return {DateTimeWithZoneId} the unpacked date time with zone id value. + * @return {DateTime} the unpacked date time with zone id value. */ function unpackDateTimeWithZoneId(unpacker, structSize, buffer, disableLosslessIntegers) { unpacker._verifyStructSize('DateTimeWithZoneId', DATE_TIME_WITH_ZONE_ID_STRUCT_SIZE, structSize); const epochSecond = unpacker.unpackInteger(buffer); const nano = unpacker.unpackInteger(buffer); - const zoneId = unpacker.unpack(buffer); + const timeZoneId = unpacker.unpack(buffer); const localDateTime = epochSecondAndNanoToLocalDateTime(epochSecond, nano); - const result = new DateTimeWithZoneId(localDateTime.year, localDateTime.month, localDateTime.day, - localDateTime.hour, localDateTime.minute, localDateTime.second, localDateTime.nanosecond, zoneId); + const result = new DateTime(localDateTime.year, localDateTime.month, localDateTime.day, + localDateTime.hour, localDateTime.minute, localDateTime.second, localDateTime.nanosecond, null, timeZoneId); return convertIntegerPropsIfNeeded(result, disableLosslessIntegers); } diff --git a/src/v1/temporal-types.js b/src/v1/temporal-types.js index 31468203c..7377fd3f3 100644 --- a/src/v1/temporal-types.js +++ b/src/v1/temporal-types.js @@ -18,6 +18,7 @@ */ import {dateToIsoString, durationToIsoString, timeToIsoString, timeZoneOffsetToIsoString} from './internal/temporal-util'; +import {newError} from './error'; const IDENTIFIER_PROPERTY_ATTRIBUTES = { value: true, @@ -30,8 +31,7 @@ const LOCAL_TIME_IDENTIFIER_PROPERTY = '__isLocalTime__'; const TIME_IDENTIFIER_PROPERTY = '__isTime__'; const DATE_IDENTIFIER_PROPERTY = '__isDate__'; const LOCAL_DATE_TIME_IDENTIFIER_PROPERTY = '__isLocalDateTime__'; -const DATE_TIME_WITH_ZONE_OFFSET_IDENTIFIER_PROPERTY = '__isDateTimeWithZoneOffset__'; -const DATE_TIME_WITH_ZONE_ID_IDENTIFIER_PROPERTY = '__isDateTimeWithZoneId__'; +const DATE_TIME_IDENTIFIER_PROPERTY = '__isDateTime__'; /** * Represents an ISO 8601 duration. Contains both date-based values (years, months, days) and time-based values (seconds, nanoseconds). @@ -119,19 +119,19 @@ export class Time { * @param {Integer|number} minute the minute for the new local time. * @param {Integer|number} second the second for the new local time. * @param {Integer|number} nanosecond the nanosecond for the new local time. - * @param {Integer|number} offsetSeconds the time zone offset in seconds. + * @param {Integer|number} timeZoneOffsetSeconds the time zone offset in seconds. */ - constructor(hour, minute, second, nanosecond, offsetSeconds) { + constructor(hour, minute, second, nanosecond, timeZoneOffsetSeconds) { this.hour = hour; this.minute = minute; this.second = second; this.nanosecond = nanosecond; - this.offsetSeconds = offsetSeconds; + this.timeZoneOffsetSeconds = timeZoneOffsetSeconds; Object.freeze(this); } toString() { - return timeToIsoString(this.hour, this.minute, this.second, this.nanosecond) + timeZoneOffsetToIsoString(this.offsetSeconds); + return timeToIsoString(this.hour, this.minute, this.second, this.nanosecond) + timeZoneOffsetToIsoString(this.timeZoneOffsetSeconds); } } @@ -226,22 +226,23 @@ export function isLocalDateTime(obj) { /** * Represents an instant capturing the date, the time and the timezone identifier. - * Created DateTimeWithZoneOffset objects are frozen with {@link Object#freeze()} in constructor and thus immutable. + * Created DateTime objects are frozen with {@link Object#freeze()} in constructor and thus immutable. */ -export class DateTimeWithZoneOffset { +export class DateTime { /** * @constructor - * @param {Integer|number} year the year for the new local date. - * @param {Integer|number} month the month for the new local date. - * @param {Integer|number} day the day for the new local date. - * @param {Integer|number} hour the hour for the new local time. - * @param {Integer|number} minute the minute for the new local time. - * @param {Integer|number} second the second for the new local time. - * @param {Integer|number} nanosecond the nanosecond for the new local time. - * @param {Integer|number} offsetSeconds the timezone offset in seconds for the new timezone-aware date-time. + * @param {Integer|number} year the year for the new date-time. + * @param {Integer|number} month the month for the new date-time. + * @param {Integer|number} day the day for the new date-time. + * @param {Integer|number} hour the hour for the new date-time. + * @param {Integer|number} minute the minute for the new date-time. + * @param {Integer|number} second the second for the new date-time. + * @param {Integer|number} nanosecond the nanosecond for the new date-time. + * @param {Integer|number|null} timeZoneOffsetSeconds the total time zone offset in seconds for the new date-time. Either this argument or timeZoneId should be defined. + * @param {string|null} timeZoneId the time zone id for the new date-time. Either this argument or timeZoneOffsetSeconds should be defined. */ - constructor(year, month, day, hour, minute, second, nanosecond, offsetSeconds) { + constructor(year, month, day, hour, minute, second, nanosecond, timeZoneOffsetSeconds, timeZoneId) { this.year = year; this.month = month; this.day = day; @@ -249,70 +250,30 @@ export class DateTimeWithZoneOffset { this.minute = minute; this.second = second; this.nanosecond = nanosecond; - this.offsetSeconds = offsetSeconds; - Object.freeze(this); - } - toString() { - return localDateTimeToString(this.year, this.month, this.day, this.hour, this.minute, this.second, this.nanosecond) + - timeZoneOffsetToIsoString(this.offsetSeconds); - } -} - -Object.defineProperty(DateTimeWithZoneOffset.prototype, DATE_TIME_WITH_ZONE_OFFSET_IDENTIFIER_PROPERTY, IDENTIFIER_PROPERTY_ATTRIBUTES); - -/** - * Test if given object is an instance of {@link DateTimeWithZoneOffset} class. - * @param {object} obj the object to test. - * @return {boolean} true if given object is a {@link DateTimeWithZoneOffset}, false otherwise. - */ -export function isDateTimeWithZoneOffset(obj) { - return hasIdentifierProperty(obj, DATE_TIME_WITH_ZONE_OFFSET_IDENTIFIER_PROPERTY); -} - -/** - * Represents an instant capturing the date, the time and the timezone identifier. - * Created DateTimeWithZoneId objects are frozen with {@link Object#freeze()} in constructor and thus immutable. - */ -export class DateTimeWithZoneId { + const [offset, id] = verifyTimeZoneArguments(timeZoneOffsetSeconds, timeZoneId); + this.timeZoneOffsetSeconds = offset; + this.timeZoneId = id; - /** - * @constructor - * @param {Integer|number} year the year for the new local date. - * @param {Integer|number} month the month for the new local date. - * @param {Integer|number} day the day for the new local date. - * @param {Integer|number} hour the hour for the new local time. - * @param {Integer|number} minute the minute for the new local time. - * @param {Integer|number} second the second for the new local time. - * @param {Integer|number} nanosecond the nanosecond for the new local time. - * @param {string} zoneId the timezone identifier for the new timezone-aware date-time. - */ - constructor(year, month, day, hour, minute, second, nanosecond, zoneId) { - this.year = year; - this.month = month; - this.day = day; - this.hour = hour; - this.minute = minute; - this.second = second; - this.nanosecond = nanosecond; - this.zoneId = zoneId; Object.freeze(this); } toString() { - return localDateTimeToString(this.year, this.month, this.day, this.hour, this.minute, this.second, this.nanosecond) + `[${this.zoneId}]`; + const localDateTimeStr = localDateTimeToString(this.year, this.month, this.day, this.hour, this.minute, this.second, this.nanosecond); + const timeZoneStr = this.timeZoneId ? `[${this.timeZoneId}]` : timeZoneOffsetToIsoString(this.timeZoneOffsetSeconds); + return localDateTimeStr + timeZoneStr; } } -Object.defineProperty(DateTimeWithZoneId.prototype, DATE_TIME_WITH_ZONE_ID_IDENTIFIER_PROPERTY, IDENTIFIER_PROPERTY_ATTRIBUTES); +Object.defineProperty(DateTime.prototype, DATE_TIME_IDENTIFIER_PROPERTY, IDENTIFIER_PROPERTY_ATTRIBUTES); /** - * Test if given object is an instance of {@link DateTimeWithZoneId} class. + * Test if given object is an instance of {@link DateTime} class. * @param {object} obj the object to test. - * @return {boolean} true if given object is a {@link DateTimeWithZoneId}, false otherwise. + * @return {boolean} true if given object is a {@link DateTime}, false otherwise. */ -export function isDateTimeWithZoneId(obj) { - return hasIdentifierProperty(obj, DATE_TIME_WITH_ZONE_ID_IDENTIFIER_PROPERTY); +export function isDateTime(obj) { + return hasIdentifierProperty(obj, DATE_TIME_IDENTIFIER_PROPERTY); } function hasIdentifierProperty(obj, property) { @@ -322,3 +283,18 @@ function hasIdentifierProperty(obj, property) { function localDateTimeToString(year, month, day, hour, minute, second, nanosecond) { return dateToIsoString(year, month, day) + 'T' + timeToIsoString(hour, minute, second, nanosecond); } + +function verifyTimeZoneArguments(timeZoneOffsetSeconds, timeZoneId) { + const offsetDefined = timeZoneOffsetSeconds || timeZoneOffsetSeconds === 0; + const idDefined = timeZoneId && timeZoneId !== ''; + + if (offsetDefined && !idDefined) { + return [timeZoneOffsetSeconds, null]; + } else if (!offsetDefined && idDefined) { + return [null, timeZoneId]; + } else if (offsetDefined && idDefined) { + throw newError(`Unable to create DateTime with both time zone offset and id. Please specify either of them. Given offset: ${timeZoneOffsetSeconds} and id: ${timeZoneId}`); + } else { + throw newError(`Unable to create DateTime without either time zone offset or id. Please specify either of them. Given offset: ${timeZoneOffsetSeconds} and id: ${timeZoneId}`); + } +} diff --git a/test/types/v1/temporal-types.test.ts b/test/types/v1/temporal-types.test.ts index 9695cac59..e788e159a 100644 --- a/test/types/v1/temporal-types.test.ts +++ b/test/types/v1/temporal-types.test.ts @@ -19,12 +19,10 @@ import { Date, - DateTimeWithZoneId, - DateTimeWithZoneOffset, + DateTime, Duration, isDate, - isDateTimeWithZoneId, - isDateTimeWithZoneOffset, + isDateTime, isDuration, isLocalDateTime, isLocalTime, @@ -60,14 +58,14 @@ const localTime2Second1: number = localTime2.second; const localTime2Nanosecond1: number = localTime2.nanosecond; const time1: Time = new Time(int(1), int(1), int(1), int(1), int(1)); -const offset1: Integer = time1.offsetSeconds; +const offset1: Integer = time1.timeZoneOffsetSeconds; const hour1: Integer = time1.hour; const minute1: Integer = time1.minute; const second1: Integer = time1.second; const nanosecond1: Integer = time1.nanosecond; const time2: Time = new Time(1, 1, 1, 1, 1); -const offset2: number = time2.offsetSeconds; +const offset2: number = time2.timeZoneOffsetSeconds; const hour2: number = time2.hour; const minute2: number = time2.minute; const second2: number = time2.second; @@ -101,8 +99,9 @@ const minute4: number = localDateTime2.minute; const second4: number = localDateTime2.second; const nanosecond4: number = localDateTime2.nanosecond; -const dateTime1: DateTimeWithZoneOffset = new DateTimeWithZoneOffset(int(1), int(1), int(1), int(1), int(1), int(1), int(1), int(1)); -const offset3: Integer = dateTime1.offsetSeconds; +const dateTime1: DateTime = new DateTime(int(1), int(1), int(1), int(1), int(1), int(1), int(1), int(1), undefined); +const zoneId1: string | undefined = dateTime1.timeZoneId; +const offset3: Integer | undefined = dateTime1.timeZoneOffsetSeconds; const year3: Integer = dateTime1.year; const month3: Integer = dateTime1.month; const day3: Integer = dateTime1.day; @@ -111,8 +110,9 @@ const minute5: Integer = dateTime1.minute; const second5: Integer = dateTime1.second; const nanosecond5: Integer = dateTime1.nanosecond; -const dateTime2: DateTimeWithZoneOffset = new DateTimeWithZoneOffset(1, 1, 1, 1, 1, 1, 1, 1); -const offset4: number = dateTime2.offsetSeconds; +const dateTime2: DateTime = new DateTime(1, 1, 1, 1, 1, 1, 1, 1, undefined); +const zoneId2: string | undefined = dateTime2.timeZoneId; +const offset4: number | undefined = dateTime2.timeZoneOffsetSeconds; const year4: number = dateTime2.year; const month4: number = dateTime2.month; const day4: number = dateTime2.day; @@ -121,8 +121,9 @@ const minute6: number = dateTime2.minute; const second6: number = dateTime2.second; const nanosecond6: number = dateTime2.nanosecond; -const dateTime3: DateTimeWithZoneId = new DateTimeWithZoneId(int(1), int(1), int(1), int(1), int(1), int(1), int(1), "UTC"); -const zoneId1: string = dateTime3.zoneId; +const dateTime3: DateTime = new DateTime(int(1), int(1), int(1), int(1), int(1), int(1), int(1), undefined, "UTC"); +const zoneId3: string | undefined = dateTime3.timeZoneId; +const offset5: Integer | undefined = dateTime3.timeZoneOffsetSeconds; const year5: Integer = dateTime3.year; const month5: Integer = dateTime3.month; const day5: Integer = dateTime3.day; @@ -131,8 +132,9 @@ const minute7: Integer = dateTime3.minute; const second7: Integer = dateTime3.second; const nanosecond7: Integer = dateTime3.nanosecond; -const dateTime4: DateTimeWithZoneId = new DateTimeWithZoneId(1, 1, 1, 1, 1, 1, 1, "UTC"); -const zoneId2: string = dateTime4.zoneId; +const dateTime4: DateTime = new DateTime(1, 1, 1, 1, 1, 1, 1, undefined, "UTC"); +const zoneId4: string | undefined = dateTime4.timeZoneId; +const offset6: number | undefined = dateTime4.timeZoneOffsetSeconds; const year6: number = dateTime4.year; const month6: number = dateTime4.month; const day6: number = dateTime4.day; @@ -146,5 +148,4 @@ const isLocalTimeValue: boolean = isLocalTime(localTime1); const isTimeValue: boolean = isTime(time1); const isDateValue: boolean = isDate(date1); const isLocalDateTimeValue: boolean = isLocalDateTime(localDateTime1); -const isDateTimeWithZoneOffsetValue: boolean = isDateTimeWithZoneOffset(dateTime1); -const isDateTimeWithZoneIdValue: boolean = isDateTimeWithZoneId(dateTime3); +const isDateTimeValue: boolean = isDateTime(dateTime1); diff --git a/test/v1/temporal-types.test.js b/test/v1/temporal-types.test.js index 2d5a9de48..5360bfe78 100644 --- a/test/v1/temporal-types.test.js +++ b/test/v1/temporal-types.test.js @@ -329,7 +329,7 @@ describe('temporal-types', () => { testSendAndReceiveArrayOfRandomTemporalValues(() => randomLocalDateTime(), done); }); - it('should receive DateTimeWithZoneOffset', done => { + it('should receive DateTime with time zone offset', done => { if (neo4jDoesNotSupportTemporalTypes(done)) { return; } @@ -338,7 +338,7 @@ describe('temporal-types', () => { testReceiveTemporalValue('RETURN datetime({year: 1992, month: 11, day: 24, hour: 9, minute: 55, second: 42, nanosecond: 999, timezone: "+05:00"})', expectedValue, done); }); - it('should send and receive max DateTimeWithZoneOffset', done => { + it('should send and receive max DateTime with zone offset', done => { if (neo4jDoesNotSupportTemporalTypes(done)) { return; } @@ -347,7 +347,7 @@ describe('temporal-types', () => { testSendReceiveTemporalValue(maxDateTime, done); }); - it('should send and receive min DateTimeWithZoneOffset', done => { + it('should send and receive min DateTime with zone offset', done => { if (neo4jDoesNotSupportTemporalTypes(done)) { return; } @@ -356,16 +356,16 @@ describe('temporal-types', () => { testSendReceiveTemporalValue(minDateTime, done); }); - it('should send and receive DateTimeWithZoneOffset when disableLosslessIntegers=true', done => { + it('should send and receive DateTime with zone offset when disableLosslessIntegers=true', done => { if (neo4jDoesNotSupportTemporalTypes(done)) { return; } session = driverWithNativeNumbers.session(); - testSendReceiveTemporalValue(new neo4j.DateTimeWithZoneOffset(2022, 2, 7, 17, 15, 59, 12399, MAX_TIME_ZONE_OFFSET), done); + testSendReceiveTemporalValue(new neo4j.DateTime(2022, 2, 7, 17, 15, 59, 12399, MAX_TIME_ZONE_OFFSET, null), done); }); - it('should send and receive random DateTimeWithZoneOffset', done => { + it('should send and receive random DateTime with zone offset', done => { if (neo4jDoesNotSupportTemporalTypes(done)) { return; } @@ -373,7 +373,7 @@ describe('temporal-types', () => { testSendAndReceiveRandomTemporalValues(() => randomDateTimeWithZoneOffset(), done); }); - it('should send and receive array of DateTimeWithZoneOffset', done => { + it('should send and receive array of DateTime with zone offset', done => { if (neo4jDoesNotSupportTemporalTypes(done)) { return; } @@ -381,7 +381,7 @@ describe('temporal-types', () => { testSendAndReceiveArrayOfRandomTemporalValues(() => randomDateTimeWithZoneOffset(), done); }); - it('should receive DateTimeWithZoneId', done => { + it('should receive DateTime with zone id', done => { if (neo4jDoesNotSupportTemporalTypes(done)) { return; } @@ -390,7 +390,7 @@ describe('temporal-types', () => { testReceiveTemporalValue('RETURN datetime({year: 1992, month: 11, day: 24, hour: 9, minute: 55, second: 42, nanosecond: 999, timezone: "Europe/Stockholm"})', expectedValue, done); }); - it('should send and receive max DateTimeWithZoneId', done => { + it('should send and receive max DateTime with zone id', done => { if (neo4jDoesNotSupportTemporalTypes(done)) { return; } @@ -399,7 +399,7 @@ describe('temporal-types', () => { testSendReceiveTemporalValue(maxDateTime, done); }); - it('should send and receive min DateTimeWithZoneId', done => { + it('should send and receive min DateTime with zone id', done => { if (neo4jDoesNotSupportTemporalTypes(done)) { return; } @@ -408,16 +408,16 @@ describe('temporal-types', () => { testSendReceiveTemporalValue(minDateTime, done); }); - it('should send and receive DateTimeWithZoneId when disableLosslessIntegers=true', done => { + it('should send and receive DateTime with zone id when disableLosslessIntegers=true', done => { if (neo4jDoesNotSupportTemporalTypes(done)) { return; } session = driverWithNativeNumbers.session(); - testSendReceiveTemporalValue(new neo4j.DateTimeWithZoneId(2011, 11, 25, 23, 59, 59, 192378, 'Europe/Stockholm'), done); + testSendReceiveTemporalValue(new neo4j.DateTime(2011, 11, 25, 23, 59, 59, 192378, null, 'Europe/Stockholm'), done); }); - it('should send and receive random DateTimeWithZoneId', done => { + it('should send and receive random DateTime with zone id', done => { if (neo4jDoesNotSupportTemporalTypes(done)) { return; } @@ -425,7 +425,7 @@ describe('temporal-types', () => { testSendAndReceiveRandomTemporalValues(() => randomDateTimeWithZoneId(), done); }); - it('should send and receive array of DateTimeWithZoneId', done => { + it('should send and receive array of DateTime with zone id', done => { if (neo4jDoesNotSupportTemporalTypes(done)) { return; } @@ -599,14 +599,14 @@ describe('temporal-types', () => { function randomDateTimeWithZoneOffset() { const dateTime = randomDstSafeLocalDateTime(); - return new neo4j.DateTimeWithZoneOffset(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second, dateTime.nanosecond, - randomZoneOffsetSeconds()); + return new neo4j.DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second, dateTime.nanosecond, + randomZoneOffsetSeconds(), null); } function randomDateTimeWithZoneId() { const dateTime = randomDstSafeLocalDateTime(); - return new neo4j.DateTimeWithZoneId(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second, dateTime.nanosecond, - randomZoneId()); + return new neo4j.DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute, dateTime.second, dateTime.nanosecond, + null, randomZoneId()); } function randomDstSafeLocalDateTime() { @@ -683,13 +683,13 @@ describe('temporal-types', () => { } function dateTimeWithZoneOffset(year, month, day, hour, minute, second, nanosecond, offsetSeconds) { - return new neo4j.DateTimeWithZoneOffset(neo4j.int(year), neo4j.int(month), neo4j.int(day), - neo4j.int(hour), neo4j.int(minute), neo4j.int(second), neo4j.int(nanosecond), neo4j.int(offsetSeconds)); + return new neo4j.DateTime(neo4j.int(year), neo4j.int(month), neo4j.int(day), + neo4j.int(hour), neo4j.int(minute), neo4j.int(second), neo4j.int(nanosecond), neo4j.int(offsetSeconds), null); } function dateTimeWithZoneId(year, month, day, hour, minute, second, nanosecond, zoneId) { - return new neo4j.DateTimeWithZoneId(neo4j.int(year), neo4j.int(month), neo4j.int(day), - neo4j.int(hour), neo4j.int(minute), neo4j.int(second), neo4j.int(nanosecond), zoneId); + return new neo4j.DateTime(neo4j.int(year), neo4j.int(month), neo4j.int(day), + neo4j.int(hour), neo4j.int(minute), neo4j.int(second), neo4j.int(nanosecond), null, zoneId); } function randomInt(lower, upper) { diff --git a/types/v1/index.d.ts b/types/v1/index.d.ts index a3c07e9aa..f321ca030 100644 --- a/types/v1/index.d.ts +++ b/types/v1/index.d.ts @@ -20,22 +20,7 @@ import Integer, {inSafeRange, int, isInt, toNumber, toString} from "./integer"; import {Node, Path, PathSegment, Relationship, UnboundRelationship} from "./graph-types"; import {isPoint, Point} from "./spatial-types"; -import { - Date, - DateTimeWithZoneId, - DateTimeWithZoneOffset, - Duration, - isDate, - isDateTimeWithZoneId, - isDateTimeWithZoneOffset, - isDuration, - isLocalDateTime, - isLocalTime, - isTime, - LocalDateTime, - LocalTime, - Time -} from "./temporal-types"; +import {Date, DateTime, Duration, isDate, isDateTime, isDuration, isLocalDateTime, isLocalTime, isTime, LocalDateTime, LocalTime, Time} from "./temporal-types"; import {Neo4jError, PROTOCOL_ERROR, SERVICE_UNAVAILABLE, SESSION_EXPIRED} from "./error"; import Result, {Observer, StatementResult} from "./result"; import ResultSummary, {Notification, NotificationPosition, Plan, ProfiledPlan, ServerInfo, StatementStatistic} from "./result-summary"; @@ -78,8 +63,7 @@ declare const types: { Time: Time; Date: Date; LocalDateTime: LocalDateTime; - DateTimeWithZoneOffset: DateTimeWithZoneOffset; - DateTimeWithZoneId: DateTimeWithZoneId; + DateTime: DateTime; }; declare const session: { @@ -150,15 +134,13 @@ declare const forExport: { Time: Time; Date: Date; LocalDateTime: LocalDateTime; - DateTimeWithZoneOffset: DateTimeWithZoneOffset; - DateTimeWithZoneId: DateTimeWithZoneId; + DateTime: DateTime; isDuration: typeof isDuration; isLocalTime: typeof isLocalTime; isTime: typeof isTime; isDate: typeof isDate; isLocalDateTime: typeof isLocalDateTime; - isDateTimeWithZoneOffset: typeof isDateTimeWithZoneOffset; - isDateTimeWithZoneId: typeof isDateTimeWithZoneId; + isDateTime: typeof isDateTime; }; export { @@ -203,15 +185,13 @@ export { Time, Date, LocalDateTime, - DateTimeWithZoneOffset, - DateTimeWithZoneId, + DateTime, isDuration, isLocalTime, isTime, isDate, isLocalDateTime, - isDateTimeWithZoneOffset, - isDateTimeWithZoneId + isDateTime } export default forExport; diff --git a/types/v1/temporal-types.d.ts b/types/v1/temporal-types.d.ts index 53d4107e3..7eccab938 100644 --- a/types/v1/temporal-types.d.ts +++ b/types/v1/temporal-types.d.ts @@ -46,9 +46,9 @@ declare class Time { readonly minute: T; readonly second: T; readonly nanosecond: T; - readonly offsetSeconds: T; + readonly timeZoneOffsetSeconds: T; - constructor(hour: T, minute: T, second: T, nanosecond: T, offsetSeconds: T); + constructor(hour: T, minute: T, second: T, nanosecond: T, timeZoneOffsetSeconds: T); } declare class Date { @@ -73,7 +73,7 @@ declare class LocalDateTime { constructor(year: T, month: T, day: T, hour: T, minute: T, second: T, nanosecond: T); } -declare class DateTimeWithZoneOffset { +declare class DateTime { readonly year: T; readonly month: T; @@ -82,23 +82,10 @@ declare class DateTimeWithZoneOffset { readonly minute: T; readonly second: T; readonly nanosecond: T; - readonly offsetSeconds: T; + readonly timeZoneOffsetSeconds?: T; + readonly timeZoneId?: string; - constructor(year: T, month: T, day: T, hour: T, minute: T, second: T, nanosecond: T, offsetSeconds: T); -} - -declare class DateTimeWithZoneId { - - readonly year: T; - readonly month: T; - readonly day: T; - readonly hour: T; - readonly minute: T; - readonly second: T; - readonly nanosecond: T; - readonly zoneId: string; - - constructor(year: T, month: T, day: T, hour: T, minute: T, second: T, nanosecond: T, zoneId: string); + constructor(year: T, month: T, day: T, hour: T, minute: T, second: T, nanosecond: T, timeZoneOffsetSeconds?: T, timeZoneId?: string); } declare function isDuration(obj: object): boolean; @@ -111,9 +98,7 @@ declare function isDate(obj: object): boolean; declare function isLocalDateTime(obj: object): boolean; -declare function isDateTimeWithZoneOffset(obj: object): boolean; - -declare function isDateTimeWithZoneId(obj: object): boolean; +declare function isDateTime(obj: object): boolean; export { Duration, @@ -121,13 +106,11 @@ export { Time, Date, LocalDateTime, - DateTimeWithZoneOffset, - DateTimeWithZoneId, + DateTime, isDuration, isLocalTime, isTime, isDate, isLocalDateTime, - isDateTimeWithZoneOffset, - isDateTimeWithZoneId + isDateTime }