Skip to content

Commit 1f0220a

Browse files
committed
added test for ensuring pad of 0 for single digit min
1 parent e5c8086 commit 1f0220a

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ function formatAs12HourClock(time) {
88
// }
99
// return `${time} am`;
1010
// }
11-
if (hours > 12) {
12-
return `${(hours - 12).toString().padStart(2, "0")}:${(min).toString().padStart(2, "0")} pm`;
13-
}
11+
if (hours === 12) {
12+
return `${time} pm`
13+
} else if (hours > 12) {
14+
return `${(hours - 12).toString().padStart(2, "0")}:${(min).toString().padStart(2, "0")} pm`
15+
};
1416
return `${time} am`;
15-
}
17+
}
1618

1719
export {formatAs12HourClock};
1820

19-
console.log(formatAs12HourClock("18:02"));
2021

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ test("can correctly convert time with minutes for am", function(){
1616

1717
test("can correctly convert time with minutes for pm", function(){
1818
assert.equal(formatAs12HourClock("18:35"), "06:35 pm");
19+
});
20+
21+
test("can correctly convert time with minutes with 0 pad such as 12:04", function(){
22+
assert.equal(formatAs12HourClock("13:04"), "01:04 pm");
1923
});

0 commit comments

Comments
 (0)