From 77e049dc05c9bc9ddeaa30092b9211c52837e869 Mon Sep 17 00:00:00 2001 From: Andy Date: Fri, 30 Jul 2021 17:48:59 +0200 Subject: [PATCH] add missing fixTimestamp --- gt06.js | 4 +++- test/gt06.test.js | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gt06.js b/gt06.js index a0570a5..2b521c7 100644 --- a/gt06.js +++ b/gt06.js @@ -214,6 +214,7 @@ function parseLocation(data) { let parsed = { fixTime: parseDatetime(datasheet.fixTime).toISOString(), + fixTimestamp: parseDatetime(datasheet.fixTime).getTime()/1000, satCnt: (datasheet.quantity & 0xF0) >> 4, satCntActive: (datasheet.quantity & 0x0F), lat: decodeGt06Lat(datasheet.lat, datasheet.course), @@ -260,7 +261,8 @@ function parseAlarm(data) { }; let parsed = { - fixTime: parseDatetime(datasheet.fixTime), + fixTime: parseDatetime(datasheet.fixTime).toISOString(), + fixTimestamp: parseDatetime(datasheet.fixTime).getTime()/1000, satCnt: (datasheet.quantity & 0xF0) >> 4, satCntActive: (datasheet.quantity & 0x0F), lat: decodeGt06Lat(datasheet.lat, datasheet.course), diff --git a/test/gt06.test.js b/test/gt06.test.js index 494118c..327e00c 100644 --- a/test/gt06.test.js +++ b/test/gt06.test.js @@ -80,12 +80,13 @@ const locationResult = { } const timeTest = new Buffer.from('78781f1213051d0d2506c8055dae3900ec0a9584355f010603b7fc0095fe0030bfb30d0a', 'hex') -const timeTestResult = { fixTime: "2019-05-29T13:37:06.000Z" } +const timeTestResult = { fixTime: "2019-05-29T13:37:06.000Z", fixTimestamp: 1559137026 } const timeTest2 = new Buffer.from('78781f12130c14080723ca055cb28600e77082003400010603b7ac00b9b0002f6b020d0a', 'hex') const timeTest2Result = { expectsResponse: false, fixTime: '2019-12-20T08:07:35.000Z', + fixTimestamp: 1576829255, satCnt: 12, satCntActive: 10, lat: 49.978386, @@ -203,10 +204,12 @@ test('Time Test', () => { var gt06 = new Gt06(); gt06.parse(timeTest); expect(gt06.fixTime).toBe(timeTestResult.fixTime); + expect(gt06.fixTimestamp).toBe(timeTestResult.fixTimestamp); }); test('Time Test 2', () => { var gt06 = new Gt06(); gt06.parse(timeTest2); expect(gt06.fixTime).toBe(timeTest2Result.fixTime); + expect(gt06.fixTimestamp).toBe(timeTest2Result.fixTimestamp); });