# HG changeset patch # User Adrien Di Mascio # Date 1243618292 -7200 # Node ID 640a59bf5c6800aaf47a529ee26b8dbdd730f46d # Parent 78d5b57d496450e4f6b2efcbacaf48174045a5e9 [javascript] provide a strftime method to Date objects Rely on toLocaleFormat when it's available. If not, this just returns '%Y/%m/%d'. A nicer implementation will come later diff -r 78d5b57d4964 -r 640a59bf5c68 web/data/cubicweb.python.js --- a/web/data/cubicweb.python.js Fri May 29 14:43:58 2009 +0200 +++ b/web/data/cubicweb.python.js Fri May 29 19:31:32 2009 +0200 @@ -21,23 +21,23 @@ var res = new Date() res.setTime(this.getTime() + (days * ONE_DAY)) return res -} +}; Date.prototype.sub = function(days) { return this.add(-days); -} +}; Date.prototype.iadd = function(days) { // in-place add this.setTime(this.getTime() + (days * ONE_DAY)) // avoid strange rounding problems !! this.setHours(12); -} +}; Date.prototype.isub = function(days) { // in-place sub this.setTime(this.getTime() - (days * ONE_DAY)) -} +}; /* * returns the first day of the next month @@ -50,7 +50,7 @@ var d2 = new Date(this.getFullYear(), this.getMonth()+1, 1); return d2; } -} +}; /* * returns the day of week, 0 being monday, 6 being sunday @@ -58,8 +58,15 @@ Date.prototype.getRealDay = function() { // getDay() returns 0 for Sunday ==> 6 for Saturday return (this.getDay()+6) % 7; -} +}; +Date.prototype.strftime = function(fmt) { + if (this.toLocaleFormat !== undefined) { // browser dependent + return this.toLocaleFormat(fmt); + } + // XXX implement at least a decent fallback implementation + return this.getFullYear() + '/' + (this.getMonth()+1) + '/' + this.getDate(); +}; var _DATE_FORMAT_REGXES = { 'Y': new RegExp('^-?[0-9]+'),