Skip to content

Commit

Permalink
Merge pull request #39 from silicon-heaven/fix-offset
Browse files Browse the repository at this point in the history
Fix offset
  • Loading branch information
fvacek authored Oct 30, 2024
2 parents 17c994f + 1c6ce66 commit 7ea1817
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/chainpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/cpon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 7ea1817

Please sign in to comment.