Permalink
Browse files

Fix some problems with 12:00 times. Also convert some methods to utc …

…instead
  • Loading branch information...
1 parent 04c7477 commit 16af773a1316774b53805b7fc63b5e1eec34c35d @Caged committed Feb 27, 2008
Showing with 11 additions and 9 deletions.
  1. +11 −9 datetime/format.js
View
@@ -4,27 +4,29 @@ Object.extend(Date.prototype, {
* Example: new Date().strftime("%A %I:%M %p")
*/
strftime: function(format) {
- var day = this.getDay(), month = this.getMonth();
- var hours = this.getHours(), minutes = this.getMinutes();
+ var day = this.getUTCDay(), month = this.getUTCMonth();
+ var hours = this.getUTCHours(), minutes = this.getUTCMinutes();
function pad(num) { return num.toPaddedString(2); };
- return format.gsub(/\%([aAbBcdHImMpSwyY])/, function(part) {
+ return format.gsub(/\%([aAbBcdDHiImMpSwyY])/, function(part) {
switch(part[1]) {
case 'a': return $w("Sun Mon Tue Wed Thu Fri Sat")[day]; break;
case 'A': return $w("Sunday Monday Tuesday Wednesday Thursday Friday Saturday")[day]; break;
case 'b': return $w("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec")[month]; break;
case 'B': return $w("January February March April May June July August September October November December")[month]; break;
case 'c': return this.toString(); break;
- case 'd': return pad(this.getDate()); break;
+ case 'd': return this.getUTCDate(); break;
+ case 'D': return pad(this.getUTCDate()); break;
case 'H': return pad(hours); break;
- case 'I': return pad((hours + 12) % 12); break;
+ case 'i': return (hours === 12 || hours === 0) ? 12 : (hours + 12) % 12; break;
+ case 'I': return pad((hours === 12 || hours === 0) ? 12 : (hours + 12) % 12); break;
case 'm': return pad(month + 1); break;
case 'M': return pad(minutes); break;
- case 'p': return hours > 12 ? 'PM' : 'AM'; break;
- case 'S': return pad(this.getSeconds()); break;
+ case 'p': return hours > 11 ? 'PM' : 'AM'; break;
+ case 'S': return pad(this.getUTCSeconds()); break;
case 'w': return day; break;
- case 'y': return pad(this.getFullYear() % 100); break;
- case 'Y': return this.getFullYear().toString(); break;
+ case 'y': return pad(this.getUTCFullYear() % 100); break;
+ case 'Y': return this.getUTCFullYear().toString(); break;
}
}.bind(this));
}

0 comments on commit 16af773

Please sign in to comment.