Skip to content

Commit e5c8086

Browse files
committed
Testing and adding in code:
Added in time with minutes for am and pm
1 parent 29ef74a commit e5c8086

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
function formatAs12HourClock(time) {
22

33
const hours = Number(time.slice(0, 2));
4+
const min = Number(time.slice(-2));
45

6+
// if (hours > 12) {
7+
// return `${hours - 12}:${min} pm`;
8+
// }
9+
// return `${time} am`;
10+
// }
511
if (hours > 12) {
6-
return `${hours - 12}:00 pm`;
12+
return `${(hours - 12).toString().padStart(2, "0")}:${(min).toString().padStart(2, "0")} pm`;
713
}
814
return `${time} am`;
915
}
1016

1117
export {formatAs12HourClock};
18+
19+
console.log(formatAs12HourClock("18:02"));
20+

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@ test("correctly convert time after 12:00", function(){
99
test("can correctly convert morning time", function() {
1010
assert.equal(formatAs12HourClock("08:00"), "08:00 am");
1111
});
12+
13+
test("can correctly convert time with minutes for am", function(){
14+
assert.equal(formatAs12HourClock("08:35"), "08:35 am");
15+
});
16+
17+
test("can correctly convert time with minutes for pm", function(){
18+
assert.equal(formatAs12HourClock("18:35"), "06:35 pm");
19+
});

0 commit comments

Comments
 (0)