add %L for 3-digit milliseconds

This commit is contained in:
Andrew Schaaf 2011-06-07 15:18:33 -04:00
parent 2644ab016a
commit c5362e748c
2 changed files with 21 additions and 5 deletions

View file

@ -42,6 +42,19 @@
return n < 10 ? (padding + n) : n;
}
function pad3(n, padding) {
padding = padding || '0';
if (n < 10) {
return padding + padding + n;
}
else if (n < 100) {
return padding + n;
}
else {
return n;
}
}
function hours12(d) {
var hour = d.getHours();
if (hour == 0) hour = 12;
@ -101,6 +114,7 @@
case 'r': return strftime(locale.formats.r || '%I:%M:%S %p', d, locale);
case 'S': return pad(d.getSeconds());
case 's': return Math.floor(d.getTime() / 1000);
case 'L': return pad3(Math.floor(d.getTime() % 1000));
case 'T': return strftime(locale.formats.T || '%H:%M:%S', d, locale);
case 't': return '\t';
case 'u':

View file

@ -10,19 +10,21 @@ t = new Date 1307472705867
TESTS = [
["%Y", "2011", "2011"]
["%L", "867"]
["%Y", "2011"]
["%m", "06"]
["%b", "Jun", "Jun"]
["%B", "June", "June"]
["%b", "Jun"]
["%B", "June"]
["%d", null, "07"]
["%H", null, "18"]
["%M", "51", "51"]
["%M", "51"]
["%S", "45", "45"]
["%S", "45"]
["%s", "1307472705"]
]