deno.land / x / dayjs@v1.11.5 / test / get-set.test.js

get-set.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
import moment from 'moment'import MockDate from 'mockdate'import dayjs from '../src'
beforeEach(() => { MockDate.set(new Date())})
afterEach(() => { MockDate.reset()})
it('Year', () => { expect(dayjs().get('year')).toBe(moment().get('year')) expect(dayjs().year()).toBe(moment().year()) expect(dayjs().year(0).valueOf()).toBe(moment().year(0).valueOf()) expect(dayjs().year(2000).valueOf()).toBe(moment().year(2000).valueOf())})
it('Month', () => { expect(dayjs().get('month')).toBe(moment().get('month')) expect(dayjs().month()).toBe(moment().month()) expect(dayjs().month(0).valueOf()).toBe(moment().month(0).valueOf()) expect(dayjs().month(1).valueOf()).toBe(moment().month(1).valueOf())})
it('Day of Week', () => { expect(dayjs().get('day')).toBe(moment().get('day')) expect(dayjs().day()).toBe(moment().day()) expect(dayjs().day(0).format()).toBe(moment().day(0).format()) expect(dayjs().day(1).format()).toBe(moment().day(1).format())})
it('Date', () => { expect(dayjs().get('date')).toBe(moment().get('date')) expect(dayjs().date()).toBe(moment().date()) expect(dayjs().date(0).valueOf()).toBe(moment().date(0).valueOf()) expect(dayjs().date(1).valueOf()).toBe(moment().date(1).valueOf())})
it('Hour', () => { expect(dayjs().get('hour')).toBe(moment().get('hour')) expect(dayjs().hour()).toBe(moment().hour()) expect(dayjs().hour(0).valueOf()).toBe(moment().hour(0).valueOf()) expect(dayjs().hour(1).valueOf()).toBe(moment().hour(1).valueOf())})
it('Minute', () => { expect(dayjs().get('minute')).toBe(moment().get('minute')) expect(dayjs().minute()).toBe(moment().minute()) expect(dayjs().minute(0).valueOf()).toBe(moment().minute(0).valueOf()) expect(dayjs().minute(1).valueOf()).toBe(moment().minute(1).valueOf())})
it('Second', () => { expect(dayjs().get('second')).toBe(moment().get('second')) expect(dayjs().second()).toBe(moment().second()) expect(dayjs().second(0).valueOf()).toBe(moment().second(0).valueOf()) expect(dayjs().second(1).valueOf()).toBe(moment().second(1).valueOf())})
it('Millisecond', () => { expect(dayjs().get('millisecond')).toBe(moment().get('millisecond')) expect(dayjs().millisecond()).toBe(moment().millisecond()) expect(dayjs().millisecond(0).valueOf()).toBe(moment().millisecond(0).valueOf()) expect(dayjs().millisecond(1).valueOf()).toBe(moment().millisecond(1).valueOf())})
it('Set Day', () => { expect(dayjs().set('date', 30).valueOf()).toBe(moment().set('date', 30).valueOf())})
it('Set Day of Week', () => { expect(dayjs().set('day', 0).valueOf()).toBe(moment().set('day', 0).valueOf())})
it('Set Month', () => { expect(dayjs().set('month', 11).valueOf()).toBe(moment().set('month', 11).valueOf())})
it('Set Year', () => { expect(dayjs().set('year', 2008).valueOf()).toBe(moment().set('year', 2008).valueOf())})
it('Set Hour', () => { expect(dayjs().set('hour', 6).valueOf()).toBe(moment().set('hour', 6).valueOf())})
it('Set Minute', () => { expect(dayjs().set('minute', 59).valueOf()).toBe(moment().set('minute', 59).valueOf())})
it('Set Second', () => { expect(dayjs().set('second', 59).valueOf()).toBe(moment().set('second', 59).valueOf())})
it('Set Millisecond', () => { expect(dayjs().set('millisecond', 999).valueOf()).toBe(moment().set('millisecond', 999).valueOf())})
it('Set Month and Year in last day of month', () => { // 2011-07-31 -> 2011-02-28 const origin = dayjs('2011-07-31T14:48:00.000Z') const setMonth = origin.set('month', 1) expect(setMonth.month()).toBe(1) expect(origin.date()).toBe(31) expect(setMonth.date()).toBe(28) // 2000-02-29 -> 2001-02-28 const origin2 = dayjs('2000-02-29T14:48:00.000Z') const setYear = origin2.set('year', 2001) expect(setYear.month()).toBe(1) expect(origin2.date()).toBe(29) expect(setYear.date()).toBe(28)})
it('Set Unknown String', () => { const newDate = dayjs().set('Unknown String', 1) expect(newDate.valueOf()) .toBe(moment().set('Unknown String', 1).valueOf())})
it('Immutable Set', () => { const dayjsA = dayjs() const dayjsB = dayjsA.set('year', 2011) const momentA = moment() const momentB = momentA.set('year', 2011) expect(dayjsA.valueOf()).not.toBe(dayjsB.valueOf()) expect(momentA.valueOf()).toBe(momentB.valueOf())})

dayjs

Version Info

Tagged at
a year ago