From 39e37827c8eac0c16e1fb5ecd64792da331673f3 Mon Sep 17 00:00:00 2001 From: Hongcai Deng Date: Tue, 20 Nov 2018 15:10:43 +0800 Subject: [PATCH] fix: parse date format (#53) --- lib/utils/index.js | 4 ++-- test/utils/index.test.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 test/utils/index.test.js diff --git a/lib/utils/index.js b/lib/utils/index.js index 8090d1e..d7fe447 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -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))); }; diff --git a/test/utils/index.test.js b/test/utils/index.test.js new file mode 100644 index 0000000..bf43e43 --- /dev/null +++ b/test/utils/index.test.js @@ -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); + }); +});