Skip to content

Commit 688c146

Browse files
committed
fix for invalid time
1 parent c879f93 commit 688c146

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { format } from 'date-fns'
2+
import { isFinite } from 'lodash'
23

3-
export const getFormatTime = (time: string = '') =>
4-
format(new Date(+time * 1_000), 'HH:mm:ss.SSS')
4+
export const getFormatTime = (time: string) =>
5+
(typeof time === 'string' && isFinite(+time)
6+
? format(new Date(+time * 1_000), 'HH:mm:ss.SSS')
7+
: 'Invalid time')
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
import { getFormatTime } from '../monitorUtils'
22

33
const getOutputForFormatTime: any[] = [
4-
['1641450853.668074', '09:34:13.668'],
5-
['1641450854.612083', '09:34:14.612'],
6-
['1641450856.616102', '09:34:16.616'],
7-
['1641450858.616121', '09:34:18.616'],
4+
[undefined, 'Invalid time'],
5+
[null, 'Invalid time'],
6+
[{}, 'Invalid time'],
7+
['oeuoeu', 'Invalid time'],
8+
[1, 'Invalid time'],
9+
[11641450853, 'Invalid time'],
10+
['1641450853.668074[0', 'Invalid time'],
11+
['1641450853.668074', ':34:13.668'],
12+
['1641450854.612083', ':34:14.612'],
13+
['1641450856.616102', ':34:16.616'],
14+
['1641450858.616121', ':34:18.616'],
815
]
916

10-
describe.skip('formatToText', () => {
17+
describe('formatToText', () => {
1118
it.each(getOutputForFormatTime)('for input: %s (reply), should be output: %s',
1219
(reply, expected) => {
1320
const result = getFormatTime(reply)
14-
expect(result).toBe(expected)
21+
expect(result).toContain(expected)
1522
})
1623
})

0 commit comments

Comments
 (0)