Skip to content

Commit 5225f24

Browse files
committed
Add minutes variable and write a test to check it
1 parent 29ef74a commit 5225f24

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

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

55
if (hours > 12) {
6-
return `${hours - 12}:00 pm`;
6+
const pmHours = (hours - 12).toString().padStart(2, "0");
7+
return `${pmHours}:${minutes} pm`;
78
}
89
return `${time} am`;
910
}
1011

11-
export {formatAs12HourClock};
12+
export { formatAs12HourClock };
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import {formatAs12HourClock} from "./timeConverter.js";
1+
import { formatAs12HourClock } from "./timeConverter.js";
22
import assert from "node:assert";
33
import test from "node:test";
44

5-
test("correctly convert time after 12:00", function(){
6-
assert.equal(formatAs12HourClock("23:00"), "11:00 pm");
5+
test("correctly convert time after 12:00", function () {
6+
assert.equal(formatAs12HourClock("23:00"), "11:00 pm");
77
});
88

9-
test("can correctly convert morning time", function() {
10-
assert.equal(formatAs12HourClock("08:00"), "08:00 am");
9+
test("can correctly convert morning time", function () {
10+
assert.equal(formatAs12HourClock("08:00"), "08:00 am");
1111
});
12+
13+
test("can correctly convert minutes", () =>
14+
assert.equal(formatAs12HourClock("13:30"), "01:30 pm"));

0 commit comments

Comments
 (0)