Skip to content

Commit 77d1ade

Browse files
committed
Added in special hour of 00 to testing and adjust code.
1 parent f85f166 commit 77d1ade

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

‎format-clock-edge-cases/timeConverter.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ function formatAs12HourClock(time) {
55

66
if (hours === 12) {
77
return `${time} pm`
8+
} else if (hours === 0) {
9+
return `${(hours + 12).toString().padStart(2, "0")}:${(min).toString().padStart(2, "0")} am`
810
} else if (hours > 12) {
911
return `${(hours - 12).toString().padStart(2, "0")}:${(min).toString().padStart(2, "0")} pm`
1012
};

‎format-clock-edge-cases/timeConverter.test.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ test("correctly convert time after 12:00", function(){
88

99
test("can correctly convert morning time", function() {
1010
assert.equal(formatAs12HourClock("08:00"), "08:00 am");
11+
assert.equal(formatAs12HourClock("01:00"), "01:00 am");
1112
});
1213

1314
test("can correctly convert time with minutes for am", function(){
@@ -20,4 +21,9 @@ test("can correctly convert time with minutes for pm", function(){
2021

2122
test("can correctly convert time with minutes with 0 pad such as 12:04", function(){
2223
assert.equal(formatAs12HourClock("13:04"), "01:04 pm");
24+
});
25+
26+
test("can correctly convert time with hour being 00 to show as 12 am", function(){
27+
assert.equal(formatAs12HourClock("00:00"), "12:00 am");
28+
assert.equal(formatAs12HourClock("00:30"), "12:30 am");
2329
});

0 commit comments

Comments
 (0)