Skip to content

Commit 7eaadda

Browse files
add minute variable
1 parent 255f29d commit 7eaadda

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
function formatAs12HourClock(time) {
22
const hours = Number(time.slice(0, 2));
3+
const minutes = time.slice(-3);
34
if (hours === 0) {
4-
return `${String(hours + 12).padStart(2, "0")}${time.slice(2, 5)} am`;
5+
return `12${minutes} am`;
56
}
67
if (hours === 12) {
78
return `${time} pm`;
89
}
910
if (hours > 12) {
10-
return `${String(hours - 12).padStart(2, "0")}${time.slice(2, 5)} pm`;
11+
return `${String(hours - 12).padStart(2, "0")}${minutes} pm`;
1112
}
1213
return `${time} am`;
1314
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ test("can correctly convert afternoon with double-digit minutes", function () {
2222
assert.equal(formatAs12HourClock("13:15"), "01:15 pm");
2323
});
2424

25+
test("can correctly convert afternoon with double-digit minutes", function () {
26+
assert.equal(formatAs12HourClock("13:15"), "01:15 pm");
27+
});
28+
29+
test("can correctly convert afternoon with double-digit minutes", function () {
30+
assert.equal(formatAs12HourClock("23:59"), "11:59 pm");
31+
});
32+
2533
test("can correctly convert late evening with single-digit minutes", function () {
2634
assert.equal(formatAs12HourClock("23:05"), "11:05 pm");
2735
});

0 commit comments

Comments
 (0)