-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDate.prototype.dateAdd.js
More file actions
45 lines (45 loc) · 1.4 KB
/
Date.prototype.dateAdd.js
File metadata and controls
45 lines (45 loc) · 1.4 KB
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
if(!Date.prototype.dateAdd) {
Date.prototype.dateAdd = function(size,value) {
value = parseInt(value);
var incr = 0;
switch (size) {
case 'day':
incr = value * 24;
this.dateAdd('hour',incr);
break;
case 'hour':
incr = value * 60;
this.dateAdd('minute',incr);
break;
case 'week':
incr = value * 7;
this.dateAdd('day',incr);
break;
case 'minute':
incr = value * 60;
this.dateAdd('second',incr);
break;
case 'second':
incr = value * 1000;
this.dateAdd('millisecond',incr);
break;
case 'month':
value = value + this.getUTCMonth();
if (value/12>0) {
this.dateAdd('year',value/12);
value = value % 12;
}
this.setUTCMonth(value);
break;
case 'millisecond':
this.setTime(this.getTime() + value);
break;
case 'year':
this.setFullYear(this.getUTCFullYear()+value);
break;
default:
throw new Error('Invalid date increment passed');
break;
}
}
}