parseTime.spec.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. import { parseTime } from '@/utils/index.js'
  11. describe('Utils:parseTime', () => {
  12. const d = new Date('2018-07-13 17:54:01') // "2018-07-13 17:54:01"
  13. it('timestamp', () => {
  14. expect(parseTime(d)).toBe('2018-07-13 17:54:01')
  15. })
  16. it('timestamp string', () => {
  17. expect(parseTime((d + ''))).toBe('2018-07-13 17:54:01')
  18. })
  19. it('ten digits timestamp', () => {
  20. expect(parseTime((d / 1000).toFixed(0))).toBe('2018-07-13 17:54:01')
  21. })
  22. it('new Date', () => {
  23. expect(parseTime(new Date(d))).toBe('2018-07-13 17:54:01')
  24. })
  25. it('format', () => {
  26. expect(parseTime(d, '{y}-{m}-{d} {h}:{i}')).toBe('2018-07-13 17:54')
  27. expect(parseTime(d, '{y}-{m}-{d}')).toBe('2018-07-13')
  28. expect(parseTime(d, '{y}/{m}/{d} {h}-{i}')).toBe('2018/07/13 17-54')
  29. })
  30. it('get the day of the week', () => {
  31. expect(parseTime(d, '{a}')).toBe('五') // 星期五
  32. })
  33. it('get the day of the week', () => {
  34. expect(parseTime(+d + 1000 * 60 * 60 * 24 * 2, '{a}')).toBe('日') // 星期日
  35. })
  36. it('empty argument', () => {
  37. expect(parseTime()).toBeNull()
  38. })
  39. })