Skip to content

Commit 6891773

Browse files
committed
Write a test and change code to correctly convert midday hours
1 parent d136f28 commit 6891773

2 files changed

Lines changed: 5 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
@@ -4,6 +4,8 @@ function formatAs12HourClock(time) {
44

55
if (hours === 0) {
66
return `12:${minutes} am`;
7+
} else if (hours === 12) {
8+
return `12:${minutes} pm`;
79
} else if (hours > 12) {
810
const pmHours = (hours - 12).toString().padStart(2, "0");
911
return `${pmHours}:${minutes} pm`;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ test("can correctly convert hours before midday", () =>
2121

2222
test("can correctly convert midnight", () =>
2323
assert.equal(formatAs12HourClock("00:00"), "12:00 am"));
24+
25+
test("can correctly convert midday", () =>
26+
assert.equal(formatAs12HourClock("12:00"), "12:00 pm"));

0 commit comments

Comments
 (0)