parseTime.spec.js 981 B

12345678910111213141516171819202122232425262728
  1. import { parseTime } from '@/utils/index.js'
  2. describe('Utils:parseTime', () => {
  3. const d = new Date('2018-07-13 17:54:01') // "2018-07-13 17:54:01"
  4. it('timestamp', () => {
  5. expect(parseTime(d)).toBe('2018-07-13 17:54:01')
  6. })
  7. it('ten digits timestamp', () => {
  8. expect(parseTime((d / 1000).toFixed(0))).toBe('2018-07-13 17:54:01')
  9. })
  10. it('new Date', () => {
  11. expect(parseTime(new Date(d))).toBe('2018-07-13 17:54:01')
  12. })
  13. it('format', () => {
  14. expect(parseTime(d, '{y}-{m}-{d} {h}:{i}')).toBe('2018-07-13 17:54')
  15. expect(parseTime(d, '{y}-{m}-{d}')).toBe('2018-07-13')
  16. expect(parseTime(d, '{y}/{m}/{d} {h}-{i}')).toBe('2018/07/13 17-54')
  17. })
  18. it('get the day of the week', () => {
  19. expect(parseTime(d, '{a}')).toBe('五') // 星期五
  20. })
  21. it('get the day of the week', () => {
  22. expect(parseTime(+d + 1000 * 60 * 60 * 24 * 2, '{a}')).toBe('日') // 星期日
  23. })
  24. it('empty argument', () => {
  25. expect(parseTime()).toBeNull()
  26. })
  27. })