This commit is contained in:
James Campos 2011-08-02 16:32:04 -07:00
parent 20e3d8f697
commit 3dbe03300e
2 changed files with 77 additions and 89 deletions

View File

@ -1950,25 +1950,9 @@
foo: function() { foo: function() {
var code; var code;
code = conf['time'].replace(/%([A-Za-z])/g, function(s, c) { code = conf['time'].replace(/%([A-Za-z])/g, function(s, c) {
switch (c) { if (c in Time.formatters) {
case 'a': return "' + Time.formatters." + c + "() + '";
case 'A': } else {
case 'b':
case 'B':
case 'd':
case 'e':
case 'H':
case 'I':
case 'k':
case 'l':
case 'm':
case 'M':
case 'p':
case 'P':
case 'y':
return "' + Time." + c + "() + '";
break;
default:
return s; return s;
} }
}); });
@ -1983,58 +1967,60 @@
return n; return n;
} }
}, },
formatters: {
a: function() { a: function() {
return this.day[this.date.getDay()].slice(0, 3); return Time.day[Time.date.getDay()].slice(0, 3);
}, },
A: function() { A: function() {
return this.day[this.date.getDay()]; return Time.day[Time.date.getDay()];
}, },
b: function() { b: function() {
return this.month[this.date.getMonth()].slice(0, 3); return Time.month[Time.date.getMonth()].slice(0, 3);
}, },
B: function() { B: function() {
return this.month[this.date.getMonth()]; return Time.month[Time.date.getMonth()];
}, },
d: function() { d: function() {
return this.zeroPad(this.date.getDate()); return Time.zeroPad(Time.date.getDate());
}, },
e: function() { e: function() {
return this.date.getDate(); return Time.date.getDate();
}, },
H: function() { H: function() {
return this.zeroPad(this.date.getHours()); return Time.zeroPad(Time.date.getHours());
}, },
I: function() { I: function() {
return this.zeroPad(this.date.getHours() % 12 || 12); return Time.zeroPad(Time.date.getHours() % 12 || 12);
}, },
k: function() { k: function() {
return this.date.getHours(); return Time.date.getHours();
}, },
l: function() { l: function() {
return this.date.getHours() % 12 || 12; return Time.date.getHours() % 12 || 12;
}, },
m: function() { m: function() {
return this.zeroPad(this.date.getMonth() + 1); return Time.zeroPad(Time.date.getMonth() + 1);
}, },
M: function() { M: function() {
return this.zeroPad(this.date.getMinutes()); return Time.zeroPad(Time.date.getMinutes());
}, },
p: function() { p: function() {
if (this.date.getHours() < 12) { if (Time.date.getHours() < 12) {
return 'AM'; return 'AM';
} else { } else {
return 'PM'; return 'PM';
} }
}, },
P: function() { P: function() {
if (this.date.getHours() < 12) { if (Time.date.getHours() < 12) {
return 'am'; return 'am';
} else { } else {
return 'pm'; return 'pm';
} }
}, },
y: function() { y: function() {
return this.date.getFullYear() - 2000; return Time.date.getFullYear() - 2000;
}
} }
}; };
titlePost = { titlePost = {

View File

@ -1557,9 +1557,10 @@ Time =
$.replace s, time $.replace s, time
foo: -> foo: ->
code = conf['time'].replace /%([A-Za-z])/g, (s, c) -> code = conf['time'].replace /%([A-Za-z])/g, (s, c) ->
switch c if c of Time.formatters
when 'a', 'A', 'b', 'B', 'd', 'e', 'H', 'I', 'k', 'l', 'm', 'M', 'p', 'P', 'y' then "' + Time.#{c}() + '" "' + Time.formatters.#{c}() + '"
else s else
s
Time.funk = Function 'Time', "return '#{code}'" Time.funk = Function 'Time', "return '#{code}'"
day: [ day: [
'Sunday' 'Sunday'
@ -1585,21 +1586,22 @@ Time =
'December' 'December'
] ]
zeroPad: (n) -> if n < 10 then '0' + n else n zeroPad: (n) -> if n < 10 then '0' + n else n
a: -> @day[@date.getDay()][...3] formatters:
A: -> @day[@date.getDay()] a: -> Time.day[Time.date.getDay()][...3]
b: -> @month[@date.getMonth()][...3] A: -> Time.day[Time.date.getDay()]
B: -> @month[@date.getMonth()] b: -> Time.month[Time.date.getMonth()][...3]
d: -> @zeroPad @date.getDate() B: -> Time.month[Time.date.getMonth()]
e: -> @date.getDate() d: -> Time.zeroPad Time.date.getDate()
H: -> @zeroPad @date.getHours() e: -> Time.date.getDate()
I: -> @zeroPad @date.getHours() % 12 or 12 H: -> Time.zeroPad Time.date.getHours()
k: -> @date.getHours() I: -> Time.zeroPad Time.date.getHours() % 12 or 12
l: -> @date.getHours() % 12 or 12 k: -> Time.date.getHours()
m: -> @zeroPad @date.getMonth() + 1 l: -> Time.date.getHours() % 12 or 12
M: -> @zeroPad @date.getMinutes() m: -> Time.zeroPad Time.date.getMonth() + 1
p: -> if @date.getHours() < 12 then 'AM' else 'PM' M: -> Time.zeroPad Time.date.getMinutes()
P: -> if @date.getHours() < 12 then 'am' else 'pm' p: -> if Time.date.getHours() < 12 then 'AM' else 'PM'
y: -> @date.getFullYear() - 2000 P: -> if Time.date.getHours() < 12 then 'am' else 'pm'
y: -> Time.date.getFullYear() - 2000
titlePost = titlePost =
init: -> init: ->