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..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: { @@ -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; } 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];