Skip to content

Commit

Permalink
Bug fix #3: midnight and noon was incorrectly formatted when using 12…
Browse files Browse the repository at this point in the history
…-hour clock.
  • Loading branch information
dmester committed May 17, 2017
1 parent 4a6adec commit f56a6df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/stringformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,8 @@ var sffjs = (function() {
// Hour
match == "HH" ? numberPair(hour) :
match == "H" ? hour :
match == "hh" ? numberPair((hour - 1) % 12 + 1) :
match == "h" ? (hour - 1) % 12 + 1 :
match == "hh" ? numberPair(hour % 12 || 12) :
match == "h" ? hour % 12 || 12 :

// Minute
match == "mm" ? numberPair(minute) :
Expand Down
16 changes: 15 additions & 1 deletion src/stringformat.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,21 @@
assert.formatsTo("4/2/1989 6:20:33 PM", "{0:G}", dtpm);
assert.formatsTo("April 2", "{0:M}", dtpm);
assert.formatsTo("April 2", "{0:m}", dtpm);


assert.formatsTo("12:30 AM", "{0:hh:mm tt}", new Date(2000, 0, 1, 00, 30, 00));
assert.formatsTo("01:30 AM", "{0:hh:mm tt}", new Date(2000, 0, 1, 01, 30, 00));
assert.formatsTo("11:30 AM", "{0:hh:mm tt}", new Date(2000, 0, 1, 11, 30, 00));
assert.formatsTo("12:30 PM", "{0:hh:mm tt}", new Date(2000, 0, 1, 12, 30, 00));
assert.formatsTo("01:30 PM", "{0:hh:mm tt}", new Date(2000, 0, 1, 13, 30, 00));
assert.formatsTo("11:30 PM", "{0:hh:mm tt}", new Date(2000, 0, 1, 23, 30, 00));

assert.formatsTo("12:30 AM", "{0:h:mm tt}", new Date(2000, 0, 1, 00, 30, 00));
assert.formatsTo("1:30 AM", "{0:h:mm tt}", new Date(2000, 0, 1, 01, 30, 00));
assert.formatsTo("11:30 AM", "{0:h:mm tt}", new Date(2000, 0, 1, 11, 30, 00));
assert.formatsTo("12:30 PM", "{0:h:mm tt}", new Date(2000, 0, 1, 12, 30, 00));
assert.formatsTo("1:30 PM", "{0:h:mm tt}", new Date(2000, 0, 1, 13, 30, 00));
assert.formatsTo("11:30 PM", "{0:h:mm tt}", new Date(2000, 0, 1, 23, 30, 00));

test.section("Quoted text");
assert.formatsTo("06mm33", "{0:hh'mm'ss}", dtam);
assert.formatsTo("06mm33", "{0:hh\"mm\"ss}", dtam);
Expand Down

0 comments on commit f56a6df

Please sign in to comment.