Skip to content

Commit

Permalink
add %L for 3-digit milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewschaaf committed Jun 7, 2011
1 parent 2644ab0 commit c5362e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
14 changes: 14 additions & 0 deletions lib/index.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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':
Expand Down
12 changes: 7 additions & 5 deletions test/test.coffee
Expand Up @@ -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"]
]
Expand Down

1 comment on commit c5362e7

@andrewschaaf
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.