1 |
|
2 | window.Date.prototype.minuteMilliSecond = 60 * 1000;
|
3 | window.Date.prototype.hourMilliSecond = 60 * 60 * 1000;
|
4 | window.Date.prototype.dayMilliSecond = 24 * 60 * 60 * 1000;
|
5 | window.Date.prototype.weekMilliSecond = 7 * 24 * 60 * 60 * 1000;
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | window.Date.prototype.year = function (year) {
|
12 | if (year) this.setYear(year);
|
13 | return this.getFullYear().toString();
|
14 | };
|
15 |
|
16 | window.Date.prototype.prevYear = function (count) {
|
17 | this.setYear(this.getFullYear() - (count || 1));
|
18 | return this;
|
19 | };
|
20 |
|
21 | window.Date.prototype.nextYear = function (count) {
|
22 | this.setYear(this.getFullYear() + (count || 1));
|
23 | return this;
|
24 | };
|
25 |
|
26 | window.Date.prototype.isLeap = function () {
|
27 | var year = this.getFullYear();
|
28 | return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
29 | };
|
30 |
|
31 | window.Date.prototype.firstYearDate = function () {
|
32 | this.setMonth(0, 1);
|
33 | return this;
|
34 | };
|
35 |
|
36 | window.Date.prototype.lastYearDate = function () {
|
37 | this.setMonth(11, 31);
|
38 | return this;
|
39 | };
|
40 |
|
41 | window.Date.prototype.getYearDate = function () {
|
42 | return this.isLeap() ? 366 : 365;
|
43 | };
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | window.Date.prototype.season = function (argCount) {
|
50 | var count = argCount || Math.ceil((this.getMonth() + 1) / 3);
|
51 |
|
52 | this.setMonth(count * 3 - 3, 1);
|
53 | return count;
|
54 | };
|
55 |
|
56 | window.Date.prototype.prevSeason = function (count) {
|
57 |
|
58 | this.setMonth(this.getMonth() - 3 * (count || 1), 1);
|
59 | return Math.ceil((this.getMonth() + 1) / 3);
|
60 | };
|
61 |
|
62 | window.Date.prototype.nextSeason = function (count) {
|
63 |
|
64 | this.setMonth(this.getMonth() + 3 * (count || 1), 1);
|
65 | return Math.ceil((this.getMonth() + 1) / 3);
|
66 | };
|
67 |
|
68 | window.Date.prototype.firstSeason = function () {
|
69 | this.season(1);
|
70 | return 1;
|
71 | };
|
72 |
|
73 | window.Date.prototype.lastSeason = function () {
|
74 | this.season(4);
|
75 | return 4;
|
76 | };
|
77 |
|
78 | window.Date.prototype.firstSeasonDate = function () {
|
79 | var count = Math.ceil((this.getMonth() + 1) / 3);
|
80 | this.setYear(this.getFullYear());
|
81 | this.setMonth(count * 3 - 3, 1);
|
82 | return this;
|
83 | };
|
84 |
|
85 | window.Date.prototype.lastSeasonDate = function () {
|
86 | var count = Math.ceil((this.getMonth() + 1) / 3);
|
87 | this.setYear(this.getFullYear());
|
88 | this.setMonth(count * 3, 0);
|
89 | return this;
|
90 | };
|
91 |
|
92 | window.Date.prototype.getSeasonDate = function () {
|
93 |
|
94 | var count = Math.ceil((this.getMonth() + 1) / 3);
|
95 |
|
96 | if (count === 1) return this.isLeap() ? 91 : 90;
|
97 | if (count === 2) return 91;
|
98 | if (count === 3 || count === 4) return 92;
|
99 | };
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | window.Date.prototype.month = function (month) {
|
105 | var targetYear = null;
|
106 | var targetMonth = null;
|
107 | var targetMaxDate = null;
|
108 |
|
109 | if (month) {
|
110 | if (/^\d{1,2}$/.test(month)) {
|
111 | targetMonth = month - 1;
|
112 | targetMaxDate = new Date(this.getFullYear(), targetMonth + 1, 0).getDate();
|
113 | if (this.getMonthDate() > targetMaxDate) {
|
114 | this.setMonth(targetMonth, targetMaxDate);
|
115 | } else {
|
116 | this.setMonth(targetMonth);
|
117 | }
|
118 | } else if (/^(\d{4}).(\d{1,2})/.test(month)) {
|
119 | var arr = month.match(/^(\d{4}).(\d{1,2})/);
|
120 | targetYear = Number(arr[1]);
|
121 | targetMonth = arr[2] - 1;
|
122 | targetMaxDate = new Date(targetYear, targetMonth + 1, 0).getDate();
|
123 | if (this.getMonthDate() > targetMaxDate) {
|
124 | this.setYear(targetYear);
|
125 | this.setMonth(targetMonth, targetMaxDate);
|
126 | } else {
|
127 | this.setYear(targetYear);
|
128 | this.setMonth(targetMonth);
|
129 | }
|
130 | }
|
131 | }
|
132 | var num = this.getMonth() + 1;
|
133 | return num < 10 ? '0' + num : num;
|
134 | };
|
135 |
|
136 | window.Date.prototype.prevMonth = function (count) {
|
137 | var targetMonth = this.getMonth() - (count || 1);
|
138 | var targetMaxDate = new Date(this.getFullYear(), targetMonth + 1, 0).getDate();
|
139 | if (this.getDate() > targetMaxDate) {
|
140 | this.setMonth(targetMonth, targetMaxDate);
|
141 | } else {
|
142 | this.setMonth(targetMonth);
|
143 | }
|
144 | return targetMonth < 10 ? '0' + targetMonth : targetMonth;
|
145 | };
|
146 |
|
147 | window.Date.prototype.nextMonth = function (count) {
|
148 | var targetMonth = this.getMonth() + (count || 1);
|
149 | var targetMaxDate = new Date(this.getFullYear(), targetMonth + 1, 0).getDate();
|
150 | if (this.getDate() > targetMaxDate) {
|
151 | this.setMonth(targetMonth, targetMaxDate);
|
152 | } else {
|
153 | this.setMonth(targetMonth);
|
154 | }
|
155 | return targetMonth < 10 ? '0' + targetMonth : targetMonth;
|
156 | };
|
157 |
|
158 | window.Date.prototype.firstMonth = function () {
|
159 | this.setMonth(0);
|
160 | return '01';
|
161 | };
|
162 |
|
163 | window.Date.prototype.lastMonth = function () {
|
164 | this.setMonth(11);
|
165 | return '12';
|
166 | };
|
167 |
|
168 | window.Date.prototype.firstMonthDate = function () {
|
169 | this.setDate(1);
|
170 | return this;
|
171 | };
|
172 |
|
173 | window.Date.prototype.lastMonthDate = function () {
|
174 | this.setMonth(this.getMonth() + 1, 0);
|
175 | return this;
|
176 | };
|
177 |
|
178 | window.Date.prototype.getMonthDate = function () {
|
179 | return new Date(this.getFullYear(), this.getMonth() + 1, '0').getDate();
|
180 | };
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 | window.Date.prototype.day = function (language) {
|
187 | var chDay = { 1: '一', 2: '二', 3: '三', 4: '四', 5: '五', 6: '六', 0: '日' };
|
188 | if (language === 'zh_cn') {
|
189 | return chDay[this.getDay()];
|
190 | }
|
191 | return this.getDay();
|
192 | };
|
193 |
|
194 | window.Date.prototype.week = function (count) {
|
195 |
|
196 | var january1 = new Date(this.getFullYear(), 0, 1);
|
197 | var january1Day = january1.getDay();
|
198 | if (january1Day === 0) january1Day = 7;
|
199 |
|
200 | if (count) {
|
201 | this.setTime(january1.getTime() + this.weekMilliSecond * count);
|
202 | return count;
|
203 | }
|
204 |
|
205 | var num = Math.ceil((this.getTime() - january1.getTime()) / this.weekMilliSecond);
|
206 | return num;
|
207 | };
|
208 |
|
209 | window.Date.prototype.prevWeek = function (count) {
|
210 | this.setTime(this.getTime() - this.weekMilliSecond * (count || 1));
|
211 | return this;
|
212 | };
|
213 |
|
214 | window.Date.prototype.nextWeek = function (count) {
|
215 | this.setTime(this.getTime() + this.weekMilliSecond * (count || 1));
|
216 | return this;
|
217 | };
|
218 |
|
219 | window.Date.prototype.sunday = function () {
|
220 | var day = this.getDay();
|
221 | this.setTime(this.getTime() - this.dayMilliSecond * day);
|
222 | return this;
|
223 | };
|
224 |
|
225 | window.Date.prototype.monday = function () {
|
226 | var day = this.getDay();
|
227 | this.setTime(this.getTime() + this.dayMilliSecond * (1 - day));
|
228 | return this;
|
229 | };
|
230 |
|
231 | window.Date.prototype.tuesday = function () {
|
232 | var day = this.getDay();
|
233 | this.setTime(this.getTime() + this.dayMilliSecond * (2 - day));
|
234 | return this;
|
235 | };
|
236 |
|
237 | window.Date.prototype.wednesday = function () {
|
238 | var day = this.getDay();
|
239 | this.setTime(this.getTime() + this.dayMilliSecond * (3 - day));
|
240 | return this;
|
241 | };
|
242 |
|
243 | window.Date.prototype.thursday = function () {
|
244 | var day = this.getDay();
|
245 | this.setTime(this.getTime() + this.dayMilliSecond * (4 - day));
|
246 | return this;
|
247 | };
|
248 |
|
249 | window.Date.prototype.friday = function () {
|
250 | var day = this.getDay();
|
251 | this.setTime(this.getTime() + this.dayMilliSecond * (5 - day));
|
252 | return this;
|
253 | };
|
254 |
|
255 | window.Date.prototype.saturday = function () {
|
256 | var day = this.getDay();
|
257 | this.setTime(this.getTime() + this.dayMilliSecond * (6 - day));
|
258 | return this;
|
259 | };
|
260 |
|
261 |
|
262 |
|
263 |
|
264 | window.Date.prototype.date = function (date) {
|
265 | if (date) this.setDate(date);
|
266 | var num = this.getDate();
|
267 | return num < 10 ? '0' + num : num;
|
268 | };
|
269 |
|
270 | window.Date.prototype.prevDate = function (count) {
|
271 | this.setTime(this.getTime() - this.dayMilliSecond * (count || 1));
|
272 | return this;
|
273 | };
|
274 |
|
275 | window.Date.prototype.nextDate = function (count) {
|
276 | this.setTime(this.getTime() + this.dayMilliSecond * (count || 1));
|
277 | return this;
|
278 | };
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 | window.Date.prototype.hour = function (hour) {
|
285 | if (hour) this.setHours(hour);
|
286 | var num = this.getHours();
|
287 | return num < 10 ? '0' + num : num;
|
288 | };
|
289 |
|
290 | window.Date.prototype.prevHour = function (count) {
|
291 | this.setTime(this.getTime() - this.hourMilliSecond * (count || 1));
|
292 | return this;
|
293 | };
|
294 |
|
295 | window.Date.prototype.nextHour = function (count) {
|
296 | this.setTime(this.getTime() + this.hourMilliSecond * (count || 1));
|
297 | return this;
|
298 | };
|
299 |
|
300 |
|
301 |
|
302 |
|
303 | window.Date.prototype.minute = function (minute) {
|
304 | if (minute) this.setMinutes(minute);
|
305 | var num = this.getMinutes();
|
306 | return num < 10 ? '0' + num : num;
|
307 | };
|
308 |
|
309 | window.Date.prototype.prevMinute = function (count) {
|
310 | this.setTime(this.getTime() - this.minuteMilliSecond * (count || 1));
|
311 | return this;
|
312 | };
|
313 |
|
314 | window.Date.prototype.nextMinute = function (count) {
|
315 | this.setTime(this.getTime() + this.minuteMilliSecond * (count || 1));
|
316 | return this;
|
317 | };
|
318 |
|
319 | window.Date.prototype.nextMinuteSpace = function (argSpace) {
|
320 | var space = argSpace ? argSpace : 5;
|
321 | var minute = this.getMinutes();
|
322 | var hasRemainder = minute % space === 0;
|
323 |
|
324 | var percentNum = Math.ceil(minute / space);
|
325 | percentNum = hasRemainder ? parseInt(percentNum, 10) + 1 : percentNum;
|
326 |
|
327 | var result = percentNum * space;
|
328 | this.setMinutes(result);
|
329 | return this.minute();
|
330 | };
|
331 |
|
332 | window.Date.prototype.prevMinuteSpace = function (argSpace) {
|
333 | var space = argSpace ? argSpace : 5;
|
334 | var minute = this.getMinutes();
|
335 | var hasRemainder = minute % space === 0;
|
336 |
|
337 | var percentNum = Math.floor(minute / space);
|
338 | percentNum = hasRemainder ? parseInt(percentNum, 10) - 1 : percentNum;
|
339 |
|
340 | var result = percentNum * space;
|
341 | this.setMinutes(result);
|
342 | return this.minute();
|
343 | };
|
344 |
|
345 |
|
346 |
|
347 |
|
348 | window.Date.prototype.diff = function (date) {
|
349 | var dateStart = this;
|
350 | var dateEnd = date;
|
351 |
|
352 | var secondMilli = 1000;
|
353 | var minuteMilli = 60 * secondMilli;
|
354 | var hourMilli = 60 * minuteMilli;
|
355 | var dayMilli = 24 * hourMilli;
|
356 |
|
357 | var timeDiff = dateEnd.getTime() - dateStart.getTime();
|
358 |
|
359 |
|
360 | var daysDiff = Math.floor(timeDiff / dayMilli);
|
361 |
|
362 | var dayMilliRemainder = timeDiff % dayMilli;
|
363 | var hoursDiff = Math.floor(dayMilliRemainder / hourMilli);
|
364 |
|
365 | var minuteMilliRemainder = dayMilliRemainder % hourMilli;
|
366 | var minutesDiff = Math.floor(minuteMilliRemainder / minuteMilli);
|
367 |
|
368 | var secondMilliRemainder = minuteMilliRemainder % minuteMilli;
|
369 | var secondsDiff = Math.round(secondMilliRemainder / secondMilli);
|
370 |
|
371 |
|
372 | var hoursAllDiff = Math.floor(timeDiff / hourMilli);
|
373 |
|
374 | var minutesAllDiff = Math.floor(timeDiff / minuteMilli);
|
375 |
|
376 | var secondsAllDiff = Math.floor(timeDiff / secondMilli);
|
377 |
|
378 | return {
|
379 | days: daysDiff,
|
380 | hours: hoursDiff,
|
381 | minutes: minutesDiff,
|
382 | seconds: secondsDiff,
|
383 | hoursAll: hoursAllDiff,
|
384 | minutesAll: minutesAllDiff,
|
385 | secondsAll: secondsAllDiff
|
386 | };
|
387 | };
|
388 |
|
389 | window.Date.prototype.compareDateTime = function (date) {
|
390 | var date1 = new Date(this);
|
391 | var date2 = new Date(date);
|
392 | date1.setSeconds(0, 0);
|
393 | date2.setSeconds(0, 0);
|
394 | var t1 = date1.getTime();
|
395 | var t2 = date2.getTime();
|
396 |
|
397 | if (t1 === t2) return 0;
|
398 | return t1 > t2 ? 1 : -1;
|
399 | };
|
400 |
|
401 | window.Date.prototype.compareDate = function (date) {
|
402 | var date1 = new Date(this);
|
403 | var date2 = new Date(date);
|
404 | date1.setHours(0, 0, 0, 0);
|
405 | date2.setHours(0, 0, 0, 0);
|
406 | var t1 = date1.getTime();
|
407 | var t2 = date2.getTime();
|
408 |
|
409 | if (t1 === t2) return 0;
|
410 | return t1 > t2 ? 1 : -1;
|
411 | };
|
412 |
|
413 | window.Date.prototype.compareMonth = function (date) {
|
414 | var date1 = new Date(this);
|
415 | var date2 = new Date(date);
|
416 | date1.setDate(0);
|
417 | date1.setHours(0, 0, 0, 0);
|
418 | date2.setDate(0);
|
419 | date2.setHours(0, 0, 0, 0);
|
420 | var t1 = date1.getTime();
|
421 | var t2 = date2.getTime();
|
422 |
|
423 | if (t1 === t2) return 0;
|
424 | return t1 > t2 ? 1 : -1;
|
425 | };
|
426 |
|
427 | window.Date.prototype.compareTime = function (date) {
|
428 | var date1 = new Date(this);
|
429 | date1.setYear(0);
|
430 | date1.setMonth(0, 0);
|
431 | date1.setSeconds(0, 0);
|
432 | var date2 = new Date();
|
433 | if (date instanceof Date) {
|
434 | date2 = date;
|
435 | } else if (/^[0-9]{2}:[0-9]{2}$/.test(date)) {
|
436 | date2.setHours(date.split(':')[0], date.split(':')[1], 0, 0);
|
437 | } else {
|
438 | console.log('请传入hh:mm的字符串,或者一个Date对象');
|
439 | return false;
|
440 | }
|
441 | date2.setYear(0);
|
442 | date2.setMonth(0, 0);
|
443 | var t1 = date1.getTime();
|
444 | var t2 = date2.getTime();
|
445 |
|
446 | if (t1 === t2) return 0;
|
447 | return t1 > t2 ? 1 : -1;
|
448 | };
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 | window.Date.prototype.expires = function (expires) {
|
455 |
|
456 | if (!expires) {
|
457 | this.nextHour(2);
|
458 | return this;
|
459 | }
|
460 |
|
461 | if (expires instanceof Date === true) {
|
462 |
|
463 | if (expires.compareDateTime(this) === 1) {
|
464 | return expires;
|
465 | }
|
466 | return this;
|
467 | }
|
468 |
|
469 | if (!isNaN(expires)) {
|
470 | this.nextHour(expires);
|
471 | return this;
|
472 | }
|
473 |
|
474 | if (expires === 'today') {
|
475 | this.setHours(0, 0, 0, 0);
|
476 | this.nextDate();
|
477 | return this;
|
478 | }
|
479 | };
|
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 | window.Date.prototype.format = function (formatStr) {
|
486 |
|
487 | var year = this.getFullYear();
|
488 | if (formatStr.indexOf('YYYY') !== -1) {
|
489 | formatStr = formatStr.replace(/YYYY/gm, year);
|
490 | }
|
491 | if (formatStr.indexOf('YY') !== -1) {
|
492 | formatStr = formatStr.replace(/YY/gm, year.substring(2, 4));
|
493 | }
|
494 |
|
495 | var month = this.getMonth() + 1;
|
496 | if (formatStr.indexOf('MM') !== -1) {
|
497 | formatStr = formatStr.replace(/MM/gm, month < 10 ? '0' + month : month);
|
498 | }
|
499 | if (formatStr.indexOf('M') !== -1) {
|
500 | formatStr = formatStr.replace(/M/gm, month);
|
501 | }
|
502 |
|
503 | var date = this.getDate();
|
504 | if (formatStr.indexOf('DD') !== -1) {
|
505 | formatStr = formatStr.replace(/DD/gm, date < 10 ? '0' + date : date);
|
506 | }
|
507 | if (formatStr.indexOf('D') !== -1) {
|
508 | formatStr = formatStr.replace(/D/gm, date);
|
509 | }
|
510 |
|
511 |
|
512 | var quarter = Math.ceil((this.getMonth() + 1) / 3);
|
513 | if (formatStr.indexOf('Q') !== -1) {
|
514 | formatStr = formatStr.replace(/Q/gm, quarter);
|
515 | }
|
516 |
|
517 |
|
518 | var week = this.week();
|
519 | if (formatStr.indexOf('WW') !== -1) {
|
520 | formatStr = formatStr.replace(/WW/gm, week < 10 ? '0' + week : week);
|
521 | }
|
522 | if (formatStr.indexOf('W') !== -1) {
|
523 | formatStr = formatStr.replace(/W/gm, week);
|
524 | }
|
525 |
|
526 | var chinaWeek = { 1: '一', 2: '二', 3: '三', 4: '四', 5: '五', 6: '六', 0: '日' };
|
527 | var day = this.getDay();
|
528 | if (formatStr.indexOf('EE') !== -1) {
|
529 | formatStr = formatStr.replace(/EE/gm, chinaWeek[day]);
|
530 | }
|
531 | if (formatStr.indexOf('E') !== -1) {
|
532 | formatStr = formatStr.replace(/E/gm, day);
|
533 | }
|
534 |
|
535 |
|
536 | var hour = this.getHours();
|
537 | if (formatStr.indexOf('hh') !== -1) {
|
538 | formatStr = formatStr.replace(/hh/gm, hour < 10 ? '0' + hour : hour);
|
539 | }
|
540 | if (formatStr.indexOf('h') !== -1) {
|
541 | formatStr = formatStr.replace(/h/gm, hour);
|
542 | }
|
543 |
|
544 | var minute = this.getMinutes();
|
545 | if (formatStr.indexOf('mm') !== -1) {
|
546 | formatStr = formatStr.replace(/mm/gm, minute < 10 ? '0' + minute : minute);
|
547 | }
|
548 | if (formatStr.indexOf('m') !== -1) {
|
549 | formatStr = formatStr.replace(/m/gm, minute);
|
550 | }
|
551 |
|
552 | var second = this.getSeconds();
|
553 | if (formatStr.indexOf('ss') !== -1) {
|
554 | formatStr = formatStr.replace(/ss/gm, second < 10 ? '0' + second : second);
|
555 | }
|
556 | if (formatStr.indexOf('s') !== -1) {
|
557 | formatStr = formatStr.replace(/s/gm, second);
|
558 | }
|
559 | return formatStr;
|
560 | };
|
561 |
|
562 |
|
563 |
|
564 |
|
565 |
|
566 | window.Date.prototype.getMonthData = function () {
|
567 |
|
568 |
|
569 | var firstDay = new Date(this).firstMonthDate();
|
570 | var firstDayIndex = firstDay.getDay();
|
571 |
|
572 | var startDayMs = firstDay.getTime() - this.dayMilliSecond * firstDayIndex;
|
573 |
|
574 | var data = [];
|
575 |
|
576 | for (var i = 0; i < 42; i++) {
|
577 | data.push(new Date());
|
578 | if (i === 0) data[0].setTime(startDayMs);else data[i].setTime(data[i - 1].getTime() + this.dayMilliSecond);
|
579 |
|
580 |
|
581 | data[i].isCurrent = false;
|
582 | if (data[i].month() === this.month()) data[i].isCurrent = true;
|
583 | }
|
584 | return data;
|
585 | };
|
586 | window.Date.prototype.getPrevMonthData = function () {
|
587 |
|
588 | var date = new Date(this);
|
589 | date.prevMonth();
|
590 | return date.getMonthData();
|
591 | };
|
592 | window.Date.prototype.getNextMonthData = function () {
|
593 |
|
594 | var date = new Date(this);
|
595 | date.nextMonth();
|
596 | return date.getMonthData();
|
597 | };
|
598 | window.Date.prototype.getCalendarData = function () {
|
599 |
|
600 | var data = this.getPrevMonthData().concat(this.getMonthData()).concat(this.getNextMonthData());
|
601 |
|
602 |
|
603 | var activeIndex = this.getDate() + new Date(this).firstMonthDate().getDay();
|
604 |
|
605 | data.activeRowIndex = Math.ceil(activeIndex / 7) - 1;
|
606 |
|
607 | data.activeIndex = activeIndex + 41;
|
608 | return data;
|
609 | };
|
610 |
|
611 | window.Date.prototype.getPrevMonth = function (count) {
|
612 |
|
613 | if (count) {
|
614 | var months = [];
|
615 | var tempDate = new Date(this);
|
616 | for (var i = 0; i < count; i++) {
|
617 | tempDate.prevMonth();
|
618 | var prevMonth = new Date(tempDate);
|
619 | months.push(prevMonth);
|
620 | }
|
621 | return months;
|
622 | }
|
623 | var date = new Date(this);
|
624 | date.prevMonth();
|
625 | return date;
|
626 | };
|
627 |
|
628 |
|
629 | window.Date.prototype.getWeekData = function () {
|
630 |
|
631 | var date = new Date(this);
|
632 | var sunday = date.sunday();
|
633 | var data = [];
|
634 | for (var i = 0; i < 7; i++) {
|
635 | data.push(new Date(sunday.getTime() + this.dayMilliSecond * i));
|
636 | }
|
637 | return data;
|
638 | };
|
639 | window.Date.prototype.getPrevWeekData = function () {
|
640 |
|
641 | var date = new Date(this);
|
642 | date.prevWeek();
|
643 | return date.getWeekData();
|
644 | };
|
645 | window.Date.prototype.getNextWeekData = function () {
|
646 |
|
647 | var date = new Date(this);
|
648 | date.nextWeek();
|
649 | return date.getWeekData();
|
650 | };
|
651 |
|
652 | window.Date.prototype.getPrevWeek = function (count) {
|
653 |
|
654 | if (count) {
|
655 | var days = [];
|
656 | var tempDate = new Date(this);
|
657 | for (var i = 0; i < count; i++) {
|
658 | tempDate.prevWeek();
|
659 | var prevWeek = new Date(tempDate);
|
660 | days.push(prevWeek);
|
661 | }
|
662 | return days;
|
663 | }
|
664 | var date = new Date(this);
|
665 | date.prevDate();
|
666 | return date;
|
667 | };
|
668 |
|
669 |
|
670 | window.Date.prototype.getPrevDate = function (count) {
|
671 |
|
672 | if (count) {
|
673 | var dates = [];
|
674 | var tempDate = new Date(this);
|
675 | for (var i = 0; i < count; i++) {
|
676 | tempDate.prevDate();
|
677 | var prevDate = new Date(tempDate);
|
678 | dates.push(prevDate);
|
679 | }
|
680 | return dates;
|
681 | }
|
682 | var date = new Date(this);
|
683 | date.prevDate();
|
684 | return date;
|
685 | };
|
686 |
|
687 |
|
688 | window.Date.parse = function (str, type) {
|
689 | var date = new Date();
|
690 | if (type === 'time') {
|
691 | if (/^[0-9]{2}:[0-9]{2}$/.test(str)) {
|
692 | date.setHours(str.split(':')[0], str.split(':')[1], 0);
|
693 | }
|
694 | return date;
|
695 | }
|
696 | if (type === 'date') {
|
697 | if (/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test(str)) {
|
698 | date.setYear(str.split('-')[0]);
|
699 | date.setMonth(str.split('-')[1], str.split('-')[2]);
|
700 | }
|
701 | return date;
|
702 | }
|
703 | if (type === 'month') {
|
704 | if (/^[0-9]{4}-[0-9]{2}$/.test(str)) {
|
705 | date.setYear(str.split('-')[0]);
|
706 | date.setMonth(str.split('-')[1]);
|
707 | }
|
708 | return date;
|
709 | }
|
710 | if (type === 'datetime') {
|
711 | if (/^[0-9]{4}-[0-9]{2}-[0-9]{2}\s[0-9]{2}:[0-9]{2}$/.test(str)) {
|
712 |
|
713 | var strArr = str.split(' ');
|
714 | var str1 = strArr[0];
|
715 | var str2 = strArr[1];
|
716 | date.setYear(str1.split('-')[0]);
|
717 | date.setMonth(str1.split('-')[1], str1.split('-')[2]);
|
718 | date.setHours(str2.split(':')[0], str2.split(':')[1], 0);
|
719 | }
|
720 | return date;
|
721 | }
|
722 | }; |
\ | No newline at end of file |