Skip to content

Commit 5890499

Browse files
authored
fix[parseTime]: fixed when pass null (#3038)
1 parent 29b4ff6 commit 5890499

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/utils/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @returns {string | null}
1010
*/
1111
export function parseTime(time, cFormat) {
12-
if (arguments.length === 0) {
12+
if (arguments.length === 0 || !time) {
1313
return null
1414
}
1515
const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'

tests/unit/utils/parseTime.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { parseTime } from '@/utils/index.js'
2+
23
describe('Utils:parseTime', () => {
34
const d = new Date('2018-07-13 17:54:01') // "2018-07-13 17:54:01"
45
it('timestamp', () => {
@@ -29,4 +30,8 @@ describe('Utils:parseTime', () => {
2930
it('empty argument', () => {
3031
expect(parseTime()).toBeNull()
3132
})
33+
34+
it('null', () => {
35+
expect(parseTime(null)).toBeNull()
36+
})
3237
})

0 commit comments

Comments
 (0)