From c6e200dc0feceee39da6a10c654c6fc0ffa0c94d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Kubern=C3=A1t?= Date: Wed, 30 Oct 2024 18:18:34 +0100 Subject: [PATCH 1/2] chainpack: Don't serialize 0 dateime offset --- package.json | 2 +- src/chainpack.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 3619f37..cd91bb1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "libshv-js", - "version": "3.4.1", + "version": "3.4.2", "description": "Typescript implementation of libshv", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", diff --git a/src/chainpack.ts b/src/chainpack.ts index 40d3ed6..98ae9bc 100644 --- a/src/chainpack.ts +++ b/src/chainpack.ts @@ -559,14 +559,14 @@ class ChainPackWriter { } let bi = BigInt(msecs); - if (dt.utc_offset !== undefined) { + if (dt.utc_offset !== undefined && dt.utc_offset !== 0) { bi <<= 7n; bi |= BigInt((dt.utc_offset / 15) & 0x7F); } bi <<= 2n; - if (dt.utc_offset !== undefined) { + if (dt.utc_offset !== undefined && dt.utc_offset !== 0) { bi |= 1n; } From 1c6ce663e4b130ff55b1b6e4ca88acbb3c4626cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Kubern=C3=A1t?= Date: Wed, 30 Oct 2024 18:19:51 +0100 Subject: [PATCH 2/2] Don't deserialize 0 offset --- src/chainpack.ts | 2 +- src/cpon.ts | 2 +- test.ts | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/chainpack.ts b/src/chainpack.ts index 98ae9bc..1c43669 100644 --- a/src/chainpack.ts +++ b/src/chainpack.ts @@ -178,7 +178,7 @@ class ChainPackReader { msec += SHV_EPOCH_MSEC; msec -= offset * 60_000; - return withOffset(new Date(msec), offset); + return withOffset(new Date(msec), offset ?? undefined); } case PackingSchema.Map: { diff --git a/src/cpon.ts b/src/cpon.ts index 41a37da..ac50553 100644 --- a/src/cpon.ts +++ b/src/cpon.ts @@ -315,7 +315,7 @@ class CponReader { // let epoch_sec = CponReader.timegm(year, month, mday, hour, min, sec); let epochMsec = Date.UTC(year, month - 1, day, hour, min, sec, msec); epochMsec -= utcOffset * 60_000; - return withOffset(new Date(epochMsec), utcOffset); + return withOffset(new Date(epochMsec), utcOffset ?? undefined); } readCString() { diff --git a/test.ts b/test.ts index a21c08f..5a297cf 100644 --- a/test.ts +++ b/test.ts @@ -64,6 +64,7 @@ for (const lst of [ ['<4:"svete">i{2:<4:"svete">[0,1]}', null], ['d"2019-05-03T11:30:00-0700"', 'd"2019-05-03T11:30:00-07"'], ['d"2018-02-02T00:00:00Z"', null], + ['d"2024-10-30T16:30:57.890Z"', null], ['d"2027-05-03T11:30:12.345+01"', null], ]) { const cpon1 = lst[0];