deno.land / x / dayjs@v1.11.5 / test / plugin / advancedFormat.test.js

advancedFormat.test.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import MockDate from 'mockdate'import moment from 'moment'import dayjs from '../../src'import advancedFormat from '../../src/plugin/advancedFormat'import isoWeek from '../../src/plugin/isoWeek'import weekOfYear from '../../src/plugin/weekOfYear'import weekYear from '../../src/plugin/weekYear'import timezone from '../../src/plugin/timezone'import utc from '../../src/plugin/utc'import '../../src/locale/zh-cn'import '../../src/locale/nl'
dayjs.extend(utc)dayjs.extend(timezone)dayjs.extend(isoWeek)dayjs.extend(weekYear)dayjs.extend(weekOfYear)dayjs.extend(advancedFormat)
beforeEach(() => { MockDate.set(new Date())})
afterEach(() => { MockDate.reset()})
it('Format of invalid date', () => { expect(dayjs(null).format('z').toLowerCase()).toEqual(moment(null).format('z').toLowerCase())})
it('Format empty string', () => { expect(dayjs().format()).toBe(moment().format())})
it('Format Quarter Q', () => { expect(dayjs().format('Q')).toBe(moment().format('Q'))})
it('Format Timestamp X x', () => { expect(dayjs().format('X')).toBe(moment().format('X')) expect(dayjs().format('x')).toBe(moment().format('x'))})
it('Format Day of Month Do 1 - 31', () => { expect(dayjs().format('Do')).toBe(moment().format('Do')) let d = '2018-05-02 00:00:00.000' expect(dayjs(d).format('Do')).toBe(moment(d).format('Do')) d = '2018-05-01 00:00:00.000' expect(dayjs(d).format('Do')).toBe(moment(d).format('Do')) d = '2018-05-03 00:00:00.000' expect(dayjs(d).format('Do')).toBe(moment(d).format('Do')) d = '2018-05-04 00:00:00.000' expect(dayjs(d).format('Do')).toBe(moment(d).format('Do')) d = '2018-05-08 00:00:00.000' expect(dayjs(d).locale('nl').format('Do')).toBe(moment(d).locale('nl').format('Do')) d = '2018-05-11' expect(dayjs(d).format('Do')).toBe(moment(d).format('Do')) d = '2018-05-12' expect(dayjs(d).format('Do')).toBe(moment(d).format('Do')) d = '2018-05-13' expect(dayjs(d).format('Do')).toBe(moment(d).format('Do')) d = '2018-05-19 00:00:00.000' expect(dayjs(d).locale('nl').format('Do')).toBe(moment(d).locale('nl').format('Do')) d = '2018-05-22' expect(dayjs(d).format('Do')).toBe(moment(d).format('Do'))})
it('Format Hour k kk 24-hour 1 - 24', () => { expect(dayjs().format('k')).toBe(moment().format('k')) expect(dayjs().format('kk')).toBe(moment().format('kk')) let d = '2018-05-02 00:00:00.000' expect(dayjs(d).format('k')).toBe('24') expect(dayjs(d).format('k')).toBe(moment(d).format('k')) expect(dayjs(d).format('kk')).toBe('24') expect(dayjs(d).format('kk')).toBe(moment(d).format('kk')) d = '2018-05-02 01:00:00.000' expect(dayjs(d).format('k')).toBe('1') expect(dayjs(d).format('k')).toBe(moment(d).format('k')) expect(dayjs(d).format('kk')).toBe('01') expect(dayjs(d).format('kk')).toBe(moment(d).format('kk')) d = '2018-05-02 23:59:59.999' expect(dayjs(d).format('k')).toBe('23') expect(dayjs(d).format('k')).toBe(moment(d).format('k')) expect(dayjs(d).format('kk')).toBe('23') expect(dayjs(d).format('kk')).toBe(moment(d).format('kk'))})
it('Format Week of Year wo', () => { const d = '2018-12-01' expect(dayjs(d).format('wo')).toBe(moment(d).format('wo')) expect(dayjs(d).locale('zh-cn').format('wo')) .toBe(moment(d).locale('zh-cn').format('wo'))})
it('Format Week of Year wo', () => { const d = '2018-12-01' expect(dayjs(d).format('wo')).toBe(moment(d).format('wo')) expect(dayjs(d).locale('zh-cn').format('wo')) .toBe(moment(d).locale('zh-cn').format('wo'))})
it('Format Week Year gggg', () => { const d = '2018-12-31' expect(dayjs(d).format('gggg')).toBe(moment(d).format('gggg'))})
it('Format Iso Week Year GGGG', () => { const d = '2021-01-01' expect(dayjs(d).format('GGGG')).toBe(moment(d).format('GGGG'))})
it('Format Iso Week of Year', () => { const d = '2021-01-01' expect(dayjs(d).format('W')).toBe(moment(d).format('W')) expect(dayjs(d).format('WW')).toBe(moment(d).format('WW'))})
it('Format offsetName z zzz', () => { const dtz = dayjs.tz('2012-03-11 01:59:59', 'America/New_York') expect(dtz.format('z')).toBe('EST') expect(dtz.format('zzz')).toBe('Eastern Standard Time') expect(dayjs().format('z')).toBeDefined() expect(dayjs().format('zzz')).toBeDefined()})
it('Skips format strings inside brackets', () => { expect(dayjs().format('[Q]')).toBe('Q') expect(dayjs().format('[Do]')).toBe('Do') expect(dayjs().format('[gggg]')).toBe('gggg') expect(dayjs().format('[GGGG]')).toBe('GGGG') expect(dayjs().format('[w]')).toBe('w') expect(dayjs().format('[ww]')).toBe('ww') expect(dayjs().format('[W]')).toBe('W') expect(dayjs().format('[WW]')).toBe('WW') expect(dayjs().format('[wo]')).toBe('wo') expect(dayjs().format('[k]')).toBe('k') expect(dayjs().format('[kk]')).toBe('kk') expect(dayjs().format('[X]')).toBe('X') expect(dayjs().format('[x]')).toBe('x')})
dayjs

Version Info

Tagged at
a year ago