Skip to content

Commit

Permalink
fix: Update objectSupport plugin to return current date time while pa…
Browse files Browse the repository at this point in the history
…rsing empty object
  • Loading branch information
iamkun authored Oct 13, 2020
1 parent 73da380 commit f56783e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/plugin/objectSupport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 12 additions & 0 deletions test/plugin/objectSupport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit f56783e

Please sign in to comment.