Skip to content

Commit

Permalink
fix[parseTime]: fixed when pass null (#3038)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-f-cooper authored and PanJiaChen committed Jun 4, 2020
1 parent b8c934c commit 2ed1951
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @returns {string | null}
*/
export function parseTime(time, cFormat) {
if (arguments.length === 0) {
if (arguments.length === 0 || !time) {
return null
}
const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/utils/parseTime.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { parseTime } from '@/utils/index.js'

describe('Utils:parseTime', () => {
const d = new Date('2018-07-13 17:54:01') // "2018-07-13 17:54:01"
it('timestamp', () => {
Expand Down Expand Up @@ -29,4 +30,8 @@ describe('Utils:parseTime', () => {
it('empty argument', () => {
expect(parseTime()).toBeNull()
})

it('null', () => {
expect(parseTime(null)).toBeNull()
})
})

0 comments on commit 2ed1951

Please sign in to comment.