Skip to content

Commit 7f13958

Browse files
committed
perf: refine code
1 parent 95ee043 commit 7f13958

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/utils/index.js

Lines changed: 1 addition & 1 deletion
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 && time != null) {
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

Lines changed: 5 additions & 0 deletions
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', () => {
@@ -24,4 +25,8 @@ describe('Utils:parseTime', () => {
2425
it('empty argument', () => {
2526
expect(parseTime()).toBeNull()
2627
})
28+
29+
it('null', () => {
30+
expect(parseTime(null)).toBeNull()
31+
})
2732
})

0 commit comments

Comments
 (0)