public
Description: Useful pieces of JavaScript. Some old, some new.
Homepage: http://alternateidea.com
Clone URL: git://github.com/Caged/javascript-bits.git
Search Repo:
Fix some problems with 12:00 times.  Also convert some methods to utc 
instead
Caged (author)
Tue Feb 26 16:48:12 -0800 2008
commit  16af773a1316774b53805b7fc63b5e1eec34c35d
tree    81a3f4eea4fb7a8ab8bec850530e20339ea6848d
parent  04c7477505d3998b9ab0ebdbdd321407f2af940a
...
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
...
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
0
@@ -4,27 +4,29 @@ Object.extend(Date.prototype, {
0
    * Example: new Date().strftime("%A %I:%M %p")
0
    */
0
   strftime: function(format) {
0
- var day = this.getDay(), month = this.getMonth();
0
- var hours = this.getHours(), minutes = this.getMinutes();
0
+ var day = this.getUTCDay(), month = this.getUTCMonth();
0
+ var hours = this.getUTCHours(), minutes = this.getUTCMinutes();
0
     function pad(num) { return num.toPaddedString(2); };
0
 
0
- return format.gsub(/\%([aAbBcdHImMpSwyY])/, function(part) {
0
+ return format.gsub(/\%([aAbBcdDHiImMpSwyY])/, function(part) {
0
       switch(part[1]) {
0
         case 'a': return $w("Sun Mon Tue Wed Thu Fri Sat")[day]; break;
0
         case 'A': return $w("Sunday Monday Tuesday Wednesday Thursday Friday Saturday")[day]; break;
0
         case 'b': return $w("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec")[month]; break;
0
         case 'B': return $w("January February March April May June July August September October November December")[month]; break;
0
         case 'c': return this.toString(); break;
0
- case 'd': return pad(this.getDate()); break;
0
+ case 'd': return this.getUTCDate(); break;
0
+ case 'D': return pad(this.getUTCDate()); break;
0
         case 'H': return pad(hours); break;
0
- case 'I': return pad((hours + 12) % 12); break;
0
+ case 'i': return (hours === 12 || hours === 0) ? 12 : (hours + 12) % 12; break;
0
+ case 'I': return pad((hours === 12 || hours === 0) ? 12 : (hours + 12) % 12); break;
0
         case 'm': return pad(month + 1); break;
0
         case 'M': return pad(minutes); break;
0
- case 'p': return hours > 12 ? 'PM' : 'AM'; break;
0
- case 'S': return pad(this.getSeconds()); break;
0
+ case 'p': return hours > 11 ? 'PM' : 'AM'; break;
0
+ case 'S': return pad(this.getUTCSeconds()); break;
0
         case 'w': return day; break;
0
- case 'y': return pad(this.getFullYear() % 100); break;
0
- case 'Y': return this.getFullYear().toString(); break;
0
+ case 'y': return pad(this.getUTCFullYear() % 100); break;
0
+ case 'Y': return this.getUTCFullYear().toString(); break;
0
       }
0
     }.bind(this));
0
   }

Comments

    No one has commented yet.