diff --git a/src/plugin/objectSupport/index.js b/src/plugin/objectSupport/index.js index 33b5a62d..4344dc40 100644 --- a/src/plugin/objectSupport/index.js +++ b/src/plugin/objectSupport/index.js @@ -9,6 +9,9 @@ export default (o, c, dayjs) => { const { date, utc } = cfg const $d = {} if (isObject(date)) { + if (!Object.keys(date).length) { + return new Date() + } const now = utc ? dayjs.utc() : dayjs() Object.keys(date).forEach((k) => { $d[prettyUnit(k)] = date[k] diff --git a/test/plugin/objectSupport.test.js b/test/plugin/objectSupport.test.js index 392bdbf7..06b10f9d 100755 --- a/test/plugin/objectSupport.test.js +++ b/test/plugin/objectSupport.test.js @@ -114,6 +114,18 @@ const tests = [ '2010-02-14 15:25:50.125' ] ] + +describe('parse empty object', () => { + it('local', () => { + expect(dayjs({}).format()) + .toBe(moment({}).format()) + }) + it('utc', () => { + expect(dayjs.utc({}).format()) + .toBe(moment.utc({}).format()) + }) +}) + it('Constructor from Object', () => { for (let i = 0; i < tests.length; i += 1) { expect(dayjs(tests[i][0]).format(fmt)).toBe(tests[i][1])