Skip to content

Commit

Permalink
chore(package): Replace moment with date-fns
Browse files Browse the repository at this point in the history
  • Loading branch information
lgaticaq committed Feb 17, 2017
1 parent c74b1a3 commit cbc72d4
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"homepage": "https://github.com/lgaticaq/tz-parser#readme",
"dependencies": {
"crc": "^3.4.4",
"moment": "^2.17.1",
"date-fns": "^1.27.2",
"node-nmea": "^1.0.3"
},
"devDependencies": {
Expand Down
7 changes: 5 additions & 2 deletions src/avl05.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const moment = require('moment');
const dateParse = require('date-fns/parse');
const nmea = require('node-nmea');
const patterns = require('./patterns');
const utils = require('./utils');
Expand Down Expand Up @@ -40,7 +40,10 @@ module.exports = raw => {
},
charge: match[33] === '1'
},
datetime: moment(`${match[32]}+00:00`, 'YYYYMMDDHHmmssZZ').toDate(),
datetime: dateParse(
match[32].replace(
/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/,
'$1-$2-$3T$4:$5:$6+00:00')),
voltage: {
battery: parseInt(match[34], 10) / 100,
inputCharge: parseInt(match[35], 10) / 100,
Expand Down
7 changes: 5 additions & 2 deletions src/avl08.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const moment = require('moment');
const dateParse = require('date-fns/parse');
const nmea = require('node-nmea');
const patterns = require('./patterns');
const utils = require('./utils');
Expand Down Expand Up @@ -43,7 +43,10 @@ module.exports = raw => {
},
charge: match[33] === '1'
},
datetime: moment(`${match[32]}+00:00`, 'YYYYMMDDHHmmssZZ').toDate(),
datetime: dateParse(
match[32].replace(
/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/,
'$1-$2-$3T$4:$5:$6+00:00')),
voltage: {
battery: parseInt(match[34], 10) / 100,
inputCharge: parseInt(match[35], 10) / 100,
Expand Down
7 changes: 5 additions & 2 deletions src/avl201.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const moment = require('moment');
const dateParse = require('date-fns/parse');
const nmea = require('node-nmea');
const patterns = require('./patterns');
const utils = require('./utils');
Expand Down Expand Up @@ -37,7 +37,10 @@ module.exports = raw => {
},
charge: match[33] === '1'
},
datetime: moment(`${match[32]}+00:00`, 'YYYYMMDDHHmmssZZ').toDate(),
datetime: dateParse(
match[32].replace(
/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/,
'$1-$2-$3T$4:$5:$6+00:00')),
voltage: {
battery: parseInt(match[34], 10) / 100,
inputCharge: parseInt(match[35], 10) / 100
Expand Down
7 changes: 5 additions & 2 deletions src/info.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const moment = require('moment');
const dateParse = require('date-fns/parse');
const patterns = require('./patterns');

module.exports = data => {
Expand All @@ -18,6 +18,9 @@ module.exports = data => {
gsm: parseInt(match[7], 10),
battery: parseFloat(match[8]),
odometer: parseFloat(match[9]),
datetime: moment(`${match[10]} +00:00`, 'DD/MM/YY HH:mm:ss ZZ').toDate()
datetime: dateParse(
match[10].replace(
/(\d{2})\/(\d{2})\/(\d{2}) (\d{2}:\d{2}:\d{2})/,
'20$3-$2-$1T$4+00:00'))
};
};
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ dashdash@^1.12.0:
dependencies:
assert-plus "^1.0.0"

date-fns@^1.27.2:
version "1.27.2"
resolved "https://registry.npmjs.org/date-fns/-/date-fns-1.27.2.tgz#ce82f420bc028356cc661fc55c0494a56a990c9c"

[email protected], debug@^2.1.1:
version "2.2.0"
resolved "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da"
Expand Down Expand Up @@ -1008,10 +1012,6 @@ mocha@^3.2.0:
mkdirp "0.5.1"
supports-color "3.1.2"

moment@^2.17.1:
version "2.17.1"
resolved "https://registry.npmjs.org/moment/-/moment-2.17.1.tgz#fed9506063f36b10f066c8b59a144d7faebe1d82"

[email protected]:
version "0.7.1"
resolved "https://registry.npmjs.org/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098"
Expand Down

0 comments on commit cbc72d4

Please sign in to comment.