long
2021-12-08 0e0365cb3abd31edcf0c09c3fc215027983dfca8
提交 | 用户 | age
2a61f6 1 import { formatTime } from '@/utils/index.js'
L 2
3 describe('Utils:formatTime', () => {
4   const d = new Date('2018-07-13 17:54:01') // "2018-07-13 17:54:01"
5   const retrofit = 5 * 1000
6
7   it('ten digits timestamp', () => {
8     expect(formatTime((d / 1000).toFixed(0))).toBe('7月13日17时54分')
9   })
10   it('test now', () => {
11     expect(formatTime(+new Date() - 1)).toBe('刚刚')
12   })
13   it('less two minute', () => {
14     expect(formatTime(+new Date() - 60 * 2 * 1000 + retrofit)).toBe('2分钟前')
15   })
16   it('less two hour', () => {
17     expect(formatTime(+new Date() - 60 * 60 * 2 * 1000 + retrofit)).toBe('2小时前')
18   })
19   it('less one day', () => {
20     expect(formatTime(+new Date() - 60 * 60 * 24 * 1 * 1000)).toBe('1天前')
21   })
22   it('more than one day', () => {
23     expect(formatTime(d)).toBe('7月13日17时54分')
24   })
25   it('format', () => {
26     expect(formatTime(d, '{y}-{m}-{d} {h}:{i}')).toBe('2018-07-13 17:54')
27     expect(formatTime(d, '{y}-{m}-{d}')).toBe('2018-07-13')
28     expect(formatTime(d, '{y}/{m}/{d} {h}-{i}')).toBe('2018/07/13 17-54')
29   })
30 })