Skip to content

Commit

Permalink
fix: parse date format (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
denghongcai authored and gxcsoccer committed Nov 20, 2018
1 parent 6d38c30 commit 39e3782
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ exports.uncompress = function(bs) {
return zlib.inflateSync(bs);
};

// 解析日期
// 解析日期(注意时区为当地时区)
exports.parseDate = function(str) {
return new Date(
Number(str.slice(0, 4)),
Number(str.slice(4, 6)) - 1,
Number(str.slice(6, 8)),
Number(str.slice(6, 8)),
Number(str.slice(8, 10)),
Number(str.slice(10, 12)),
Number(str.slice(12)));
};
Expand Down
12 changes: 12 additions & 0 deletions test/utils/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

'use strict';

const assert = require('assert');
const util = require('../../lib/utils/index');

describe('test/utils/index.test.js', () => {
it('should parseDate ok', () => {
const d = util.parseDate('2018112000000');
assert.equal(d.getTime(), 1542643200000);
});
});

0 comments on commit 39e3782

Please sign in to comment.