Skip to content

Commit

Permalink
date extend done
Browse files Browse the repository at this point in the history
  • Loading branch information
nowa committed Jun 23, 2008
1 parent 8217263 commit 287a8b6
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 3 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added examples/.DS_Store
Binary file not shown.
10 changes: 7 additions & 3 deletions examples/dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@
// var c = new b('fish', 24);
// c.check('oh');

var d = Date.now();
// alert(d.weekday());
alert(d.strftime('%Y-%m-%d %H:%M:%S, 60\\%.'));
// var d = Date.now();
// alert(d.strftime('%Y-%m-%d %H:%M:%S, 60\\%.'));

var d = new Date(2001, 5, 28);
var c = d.clone();
c.setMinutes(80);
alert(d.inspect());
</script>

</body>
Expand Down
18 changes: 18 additions & 0 deletions src/native/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ Object.extend(Date.prototype, {
}, this);
}
return format.gsub('{PER}', '%');
},

after: function(format, offset) {
var _c = this.clone();
eval('_c.set' + format + '(_c.get' + format + '() + ' + offset + ')');
return _c;
},

clone: function() {
return new Date(this.year(), this.getMonth(), this.day(), this.hour(), this.minute(), this.second(), this.msecond());
},

inspect: function() {
return "'" + this.toString() + "'";
},

toJSON: function() {
return this.inspect();
}

});
40 changes: 40 additions & 0 deletions src/native/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,42 @@

Object.extend(Number.prototype, {

seconds: function(d) {
var _d = d ? d : Date.now();
_d.setSeconds(_d.second() + this)
return _d;
},

minutes: function(d) {
var _d = d ? d : Date.now();
_d.setMinutes(_d.minute() + this)
return _d;
},

hours: function(d) {
var _d = d ? d : Date.now();
_d.setHours(_d.hour() + this)
return _d;
},

days: function(d) {
var _d = d ? d : Date.now();
_d.setDate(_d.day() + this)
return _d;
},

months: function(d) {
var _d = d ? d : Date.now();
_d.setMonth(_d.getMonth() + this)
return _d;
},

years: function(d) {
var _d = d ? d : Date.now();
_d.setFullYear(_d.year() + this)
return _d;
},

/**
* 类ruby语法的迭代
*
Expand Down Expand Up @@ -48,6 +84,10 @@ Object.extend(Number.prototype, {
*/
toJSON: function() {
return isFinite(this) ? this.toString() : 'null';
},

to_day: function() {
return this / (1000 * 60 * 60 * 24);
}

});
Expand Down
4 changes: 4 additions & 0 deletions src/native/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ Object.extend(String.prototype, {
return this.inspect(true);
},

to_i: function(radix) {
return parseInt(this, radix || 10);
},

/**
* 根据指定的filter替换JSON字符串
*
Expand Down

0 comments on commit 287a8b6

Please sign in to comment.