-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest.core.date.js
241 lines (206 loc) · 7.8 KB
/
test.core.date.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
describe('ax5.util.date TEST', function () {
/* ax5.util.date */
//Usage 01
it('ax5.util.date("2013-01-01")', function () {
var date = new Date(2013, 0, 1);
date.setHours(12);
date.setMinutes(0);
should.deepEqual(ax5.util.date('2013-01-01'), date);
});
//Usage 02
it('ax5.util.date((new Date()) , {add:{d:10} , return:"yyyy/MM/dd"})', function () {
var date = new Date();
date.setDate(date.getDate() + 10);
var str = date.getFullYear() + "/" + ax5.util.setDigit(date.getMonth() + 1, 2) + "/" + ax5.util.setDigit(date.getDate(), 2);
should.deepEqual(ax5.util.date((new Date()), {add: {d: 10}, return: 'yyyy/MM/dd'}), str);
});
//Usage 03
it('ax5.util.date("1919-03-01", {add:{d:10}, return:"yyyy/MM/dd hh:mm:ss"})', function () {
should.deepEqual(ax5.util.date("1919-03-01", {
add: {d: 10},
return: "yyyy/MM/dd hh:mm:ss"
}), '1919/03/11 12:00:00');
});
//Usage 04
it('ax5.util.date((new Date()) , {set:"firstDayOfMonth", return:"yyyy/MM/dd"})', function () {
var date = new Date();
var str = date.getFullYear() + "/" + ax5.util.setDigit(date.getMonth() + 1, 2) + "/01";
should.deepEqual(ax5.util.date((new Date()), {set: "firstDayOfMonth", return: 'yyyy/MM/dd'}), str);
});
//Usage 05
it('ax5.util.date((new Date()) , {set:"lastDayOfMonth", return:"yyyy/MM/dd"})', function () {
var date = new Date();
var str = date.getFullYear() + "/" + ax5.util.setDigit(date.getMonth() + 1, 2) + "/" + ax5.util.daysOfMonth(date.getFullYear(), date.getMonth());
should.deepEqual(ax5.util.date((new Date()), {set: "lastDayOfMonth", return: 'yyyy/MM/dd'}), str);
});
//Usage 06
it('ax5.util.date("")', function () {
var date = new Date();
should.deepEqual(ax5.util.date(""), date);
});
//Usage 07
it('ax5.util.date("1979-12-16T09:00:00") [string.length > 15]', function () {
var date = new Date();
date.setFullYear(1979, 11, 16);
date.setHours(09, 00, 00, 000);
should.deepEqual(ax5.util.date("1979-12-16T09:00:00"), date);
});
//Usage 08
it('ax5.util.date("20170411103317") [string.length == 14]', function () {
var date = new Date(2017, 3, 11);
date.setHours(10);
date.setMinutes(33);
date.setSeconds(17);
should.deepEqual(ax5.util.date("20170411103317"), date);
});
//Usage 09
it('ax5.util.date("201704") [string.length > 7]', function () {
var date = new Date(2017, 3, 12);
date.setHours(12);
should.deepEqual(ax5.util.date("20170412"), date);
});
//Usage 10
it('ax5.util.date("201704") [string.length > 4]', function () {
var date = new Date(2017, 3);
date.setHours(12);
should.deepEqual(ax5.util.date("201704"), date);
});
//Usage 11
it('ax5.util.date("2017") [string.length > 2]', function () {
var date = new Date(2017, 0);
date.setHours(12);
should.deepEqual(ax5.util.date("2017"), date);
});
//Usage 12
it('ax5.util.date("17") [string.length <= 2]', function () {
var date = new Date();
should.deepEqual(ax5.util.date("17"), date);
});
//Usage 13
it('ax5.util.date(date, {return: "yyyy-MM-dd"})', function () {
var date = new Date(2017, 3, 16);
should.deepEqual(ax5.util.date(date, {return: "yyyy-MM-dd"}), "2017-04-16");
});
//Usage 14
it('ax5.util.date(date, {return: "yyyy-MM-dd hh:mm:ss"})', function () {
var date = new Date(2017, 3, 16, 12, 30, 15);
should.deepEqual(ax5.util.date(date, {return: "yyyy-MM-dd hh:mm:ss"}), "2017-04-16 12:30:15");
});
//Usage 15
it('ax5.util.date(date, {return: "dw"})', function () {
var date = new Date(2017, 3, 16);
should.deepEqual(ax5.util.date(date, {return: "dw"}), "SUN");
});
//Usage 16
it('ax5.util.date("2017-04-17 11:00:00", {add: {h: 1}})', function () {
var date = new Date(2017, 3, 17, 12);
should.deepEqual(ax5.util.date("2017-04-17 11:00:00", {add: {h: 1}}), date);
});
//Usage 17
it('ax5.util.date("2017-04-17 11:00:00", {add: {h: 1}})', function () {
var date = new Date(2017, 3, 17, 12);
should.deepEqual(ax5.util.date("2017-04-17 11:00:00", {add: {h: 1}}), date);
});
//Usage 18
it('ax5.util.date("2017-06-17 01:55:00", {add: {h: 1}})', function () {
var date = new Date(2017, 5, 17, 2, 55);
should.deepEqual(ax5.util.date("2017-06-17 01:55:00", {add: {h: 1}}), date);
});
//Usage 19
it('ax5.util.date("2017-04-16", {add: {d: 1}})', function () {
var date = new Date(2017, 3, 17, 12);
should.deepEqual(ax5.util.date("2017-04-16", {add: {d: 1}}), date);
});
//Usage 20
it('ax5.util.date("2017-05-16", {add: {m: 1}})', function () {
var date = new Date(2017, 5, 16, 12);
should.deepEqual(ax5.util.date("2017-05-16", {add: {m: 1}}), date);
});
//Usage 21
it('ax5.util.date("2017-04-22", {add: {y: 1}})', function () {
var date = new Date(2018, 3, 22, 12);
should.deepEqual(ax5.util.date("2017-04-22", {add: {y: 1}}), date);
});
//Usage 22
it('ax5.util.date("2016-04-23", {add: {d: 1.5}, return: "dd"})', function () {
var str = "25";
should.deepEqual(ax5.util.date("2016-04-23", {add: {d: 1.5}, return: "dd"}), str);
});
/* end ax5.util.date */
});
describe('ax5.util.dday TEST', function () {
/* ax5.util.dday*/
//Usage 01
it('ax5.util.dday(new Date())', function () {
should.deepEqual(ax5.util.dday(new Date()), 0);
});
//Usage 02
it('ax5.util.dday("2016-01-29" , {today:"2016-01-28"})', function () {
should.deepEqual(ax5.util.dday("2016-01-29", {today: "2016-01-28"}), 1);
});
//Usage 03
it('ax5.util.dday("1977-03-29" , {today:"2016-01-28" , age:true})', function () {
should.deepEqual(ax5.util.dday("1977-03-29", {today: "2016-01-28", age: true}), 39);
});
/* end ax5.util.dday*/
});
describe('ax5.util.weeksOfMonth TEST', function () {
/* ax5.util.weeksOfMonth */
//Usage 01
it('ax5.util.weeksOfMonth("2015-10-01")', function () {
var obj = {
year: 2015,
month: 10,
count: 1
};
should.deepEqual(ax5.util.weeksOfMonth("2015-10-01"), obj);
});
//Usage02
it('ax5.util.weeksOfMonth("2015-09-19")', function () {
var obj = {
year: 2015,
month: 9,
count: 3
};
should.deepEqual(ax5.util.weeksOfMonth("2015-09-19"), obj);
});
//Usage03
it('ax5.util.weeksOfMonth("2016-04-30")', function () {
var obj = {
year: 2016,
month: 4,
count: 5
};
should.deepEqual(ax5.util.weeksOfMonth("2016-04-30"), obj);
});
//Usage04
it('ax5.util.weeksOfMonth("2017-04-13")', function () {
var obj = {
year: 2017,
month: 4,
count: 2
};
should.deepEqual(ax5.util.weeksOfMonth("2017-04-13"), obj);
});
/* end ax5.util.weeksOfMonth */
});
describe('ax5.util.daysOfMonth TEST', function () {
/* ax5.util.daysOfMonth*/
//Usage 01
it('ax5.util.daysOfMonth(2015,11)', function () {
should.deepEqual(ax5.util.daysOfMonth(2015, 11), 31);
});
//Usage 02
it('ax5.util.daysOfMonth(2015,1)', function () {
should.deepEqual(ax5.util.daysOfMonth(2015, 1), 28);
});
//Usage 03
it('ax5.util.daysOfMonth(2016,1)', function () {
should.deepEqual(ax5.util.daysOfMonth(2016, 1), 29);
});
//Usage 04
it('ax5.util.daysOfMonth(2016,3)', function () {
should.deepEqual(ax5.util.daysOfMonth(2016, 3), 30);
});
/* end ax5.util.daysOfMonth*/
});