Skip to content

Commit 55df210

Browse files
committed
Warning the user about the usage of timezone without offset
1 parent e7fee5e commit 55df210

11 files changed

+28
-12
lines changed

packages/bolt-connection/src/bolt/bolt-protocol-v1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default class BoltProtocol {
8787

8888
get transformer () {
8989
if (this._transformer === undefined) {
90-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config)))
90+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
9191
}
9292
return this._transformer
9393
}

packages/bolt-connection/src/bolt/bolt-protocol-v2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class BoltProtocol extends BoltProtocolV1 {
3737

3838
get transformer () {
3939
if (this._transformer === undefined) {
40-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config)))
40+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
4141
}
4242
return this._transformer
4343
}

packages/bolt-connection/src/bolt/bolt-protocol-v3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default class BoltProtocol extends BoltProtocolV2 {
4848

4949
get transformer () {
5050
if (this._transformer === undefined) {
51-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config)))
51+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
5252
}
5353
return this._transformer
5454
}

packages/bolt-connection/src/bolt/bolt-protocol-v4x0.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default class BoltProtocol extends BoltProtocolV3 {
4646

4747
get transformer () {
4848
if (this._transformer === undefined) {
49-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config)))
49+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
5050
}
5151
return this._transformer
5252
}

packages/bolt-connection/src/bolt/bolt-protocol-v4x1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default class BoltProtocol extends BoltProtocolV4 {
6767

6868
get transformer () {
6969
if (this._transformer === undefined) {
70-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config)))
70+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
7171
}
7272
return this._transformer
7373
}

packages/bolt-connection/src/bolt/bolt-protocol-v4x2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default class BoltProtocol extends BoltProtocolV41 {
3434

3535
get transformer () {
3636
if (this._transformer === undefined) {
37-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config)))
37+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
3838
}
3939
return this._transformer
4040
}

packages/bolt-connection/src/bolt/bolt-protocol-v4x3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class BoltProtocol extends BoltProtocolV42 {
3737

3838
get transformer () {
3939
if (this._transformer === undefined) {
40-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config)))
40+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
4141
}
4242
return this._transformer
4343
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class BoltProtocol extends BoltProtocolV43 {
3737

3838
get transformer () {
3939
if (this._transformer === undefined) {
40-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config)))
40+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
4141
}
4242
return this._transformer
4343
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default class BoltProtocol extends BoltProtocolV44 {
3434

3535
get transformer () {
3636
if (this._transformer === undefined) {
37-
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config)))
37+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
3838
}
3939
return this._transformer
4040
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const DATE_TIME_WITH_ZONE_OFFSET_STRUCT_SIZE = 3
4343
const DATE_TIME_WITH_ZONE_ID = 0x69
4444
const DATE_TIME_WITH_ZONE_ID_STRUCT_SIZE = 3
4545

46-
function createDateTimeWithZoneIdTransformer (config) {
46+
function createDateTimeWithZoneIdTransformer (config, logger) {
4747
const { disableLosslessIntegers, useBigInt } = config
4848
const dateTimeWithZoneIdTransformer = v4x4.createDateTimeWithZoneIdTransformer(config)
4949
return dateTimeWithZoneIdTransformer.extendsWith({
@@ -86,6 +86,12 @@ function createDateTimeWithZoneIdTransformer (config) {
8686
const offset = value.timeZoneOffsetSeconds != null
8787
? value.timeZoneOffsetSeconds
8888
: getOffsetFromZoneId(value.timeZoneId, epochSecond, value.nanosecond)
89+
90+
if (value.timeZoneOffsetSeconds == null) {
91+
logger.warn('DateTime objects without "timeZoneOffsetSeconds" property ' +
92+
'are prune to bugs related to ambiguous times. For instance, ' +
93+
'2022-10-30T2:30:00[Europe/Berlin] could be GMT+1 or GMT+2.')
94+
}
8995
const utc = epochSecond.subtract(offset)
9096

9197
const nano = int(value.nanosecond)

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ const WRITE = 'WRITE'
4444

4545
const {
4646
txConfig: { TxConfig },
47-
bookmarks: { Bookmarks }
47+
bookmarks: { Bookmarks },
48+
logger: { Logger }
4849
} = internal
4950

5051
describe('#unit BoltProtocolV5x0', () => {
@@ -517,12 +518,15 @@ describe('#unit BoltProtocolV5x0', () => {
517518
]
518519
])('should pack and unpack DateTimeWithZoneId and without offset (%s)', (_, object) => {
519520
const buffer = alloc(256)
521+
const loggerFunction = jest.fn()
520522
const protocol = new BoltProtocolV5x0(
521523
new utils.MessageRecordingConnection(),
522524
buffer,
523525
{
524526
disableLosslessIntegers: true
525-
}
527+
},
528+
undefined,
529+
new Logger('debug', loggerFunction)
526530
)
527531

528532
const packable = protocol.packable(object)
@@ -547,6 +551,12 @@ describe('#unit BoltProtocolV5x0', () => {
547551
unpacked.timeZoneId
548552
)
549553

554+
expect(loggerFunction)
555+
.toBeCalledWith('warn',
556+
'DateTime objects without "timeZoneOffsetSeconds" property ' +
557+
'are prune to bugs related to ambiguous times. For instance, ' +
558+
'2022-10-30T2:30:00[Europe/Berlin] could be GMT+1 or GMT+2.')
559+
550560
expect(unpackedDateTimeWithoutOffset).toEqual(object)
551561
})
552562
})

0 commit comments

Comments
 (0)