Skip to content

Commit a7e351d

Browse files
Fix consistent time format $ repetition
1 parent 6fc1be1 commit a7e351d

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
function formatAs12HourClock(time) {
22
const hours = Number(time.slice(0, 2));
3+
const minutes = time.slice(-2);
34

45
if (hours === 0) {
5-
return `12:${time.slice(-2)} am`;
6+
return `12:${minutes} am`;
67
}
78

89
if (hours === 12) {
910
return `${time} pm`;
1011
}
1112

1213
if (hours > 12) {
13-
return `${hours - 12}:${time.slice(-2)} pm`;
14+
return `${hours - 12}:${minutes} pm`;
1415
}
15-
return `${time} am`;
16+
return `${hours}:${minutes} am`;
1617
}
1718

1819
export { formatAs12HourClock };

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test("correctly convert time after 12:00", function () {
77
});
88

99
test("can correctly convert morning time", function () {
10-
assert.equal(formatAs12HourClock("08:00"), "08:00 am");
10+
assert.equal(formatAs12HourClock("08:00"), "8:00 am");
1111
});
1212

1313
test("can correctly convert midnight", () =>

0 commit comments

Comments
 (0)