19 |
19 |
20 Date.prototype.add = function(days) { |
20 Date.prototype.add = function(days) { |
21 var res = new Date() |
21 var res = new Date() |
22 res.setTime(this.getTime() + (days * ONE_DAY)) |
22 res.setTime(this.getTime() + (days * ONE_DAY)) |
23 return res |
23 return res |
24 } |
24 }; |
25 |
25 |
26 Date.prototype.sub = function(days) { |
26 Date.prototype.sub = function(days) { |
27 return this.add(-days); |
27 return this.add(-days); |
28 } |
28 }; |
29 |
29 |
30 Date.prototype.iadd = function(days) { |
30 Date.prototype.iadd = function(days) { |
31 // in-place add |
31 // in-place add |
32 this.setTime(this.getTime() + (days * ONE_DAY)) |
32 this.setTime(this.getTime() + (days * ONE_DAY)) |
33 // avoid strange rounding problems !! |
33 // avoid strange rounding problems !! |
34 this.setHours(12); |
34 this.setHours(12); |
35 } |
35 }; |
36 |
36 |
37 Date.prototype.isub = function(days) { |
37 Date.prototype.isub = function(days) { |
38 // in-place sub |
38 // in-place sub |
39 this.setTime(this.getTime() - (days * ONE_DAY)) |
39 this.setTime(this.getTime() - (days * ONE_DAY)) |
40 } |
40 }; |
41 |
41 |
42 /* |
42 /* |
43 * returns the first day of the next month |
43 * returns the first day of the next month |
44 */ |
44 */ |
45 Date.prototype.nextMonth = function() { |
45 Date.prototype.nextMonth = function() { |
48 return d; |
48 return d; |
49 } else { |
49 } else { |
50 var d2 = new Date(this.getFullYear(), this.getMonth()+1, 1); |
50 var d2 = new Date(this.getFullYear(), this.getMonth()+1, 1); |
51 return d2; |
51 return d2; |
52 } |
52 } |
53 } |
53 }; |
54 |
54 |
55 /* |
55 /* |
56 * returns the day of week, 0 being monday, 6 being sunday |
56 * returns the day of week, 0 being monday, 6 being sunday |
57 */ |
57 */ |
58 Date.prototype.getRealDay = function() { |
58 Date.prototype.getRealDay = function() { |
59 // getDay() returns 0 for Sunday ==> 6 for Saturday |
59 // getDay() returns 0 for Sunday ==> 6 for Saturday |
60 return (this.getDay()+6) % 7; |
60 return (this.getDay()+6) % 7; |
61 } |
61 }; |
62 |
62 |
|
63 Date.prototype.strftime = function(fmt) { |
|
64 if (this.toLocaleFormat !== undefined) { // browser dependent |
|
65 return this.toLocaleFormat(fmt); |
|
66 } |
|
67 // XXX implement at least a decent fallback implementation |
|
68 return this.getFullYear() + '/' + (this.getMonth()+1) + '/' + this.getDate(); |
|
69 }; |
63 |
70 |
64 var _DATE_FORMAT_REGXES = { |
71 var _DATE_FORMAT_REGXES = { |
65 'Y': new RegExp('^-?[0-9]+'), |
72 'Y': new RegExp('^-?[0-9]+'), |
66 'd': new RegExp('^[0-9]{1,2}'), |
73 'd': new RegExp('^[0-9]{1,2}'), |
67 'm': new RegExp('^[0-9]{1,2}'), |
74 'm': new RegExp('^[0-9]{1,2}'), |