Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix offset #39

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading