Skip to content

Commit cf1ca72

Browse files
committed
Ensured extensions are added correctly and formatted document
1 parent 158eba2 commit cf1ca72

2 files changed

Lines changed: 24 additions & 27 deletions

File tree

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
function formatAs12HourClock(time) {
2-
32
const hours = Number(time.slice(0, 2));
43
const min = Number(time.slice(-2));
54

65
if (hours === 12) {
7-
return `${time} pm`
6+
return `${time} pm`;
87
} else if (hours === 0) {
9-
return `${(hours + 12).toString().padStart(2, "0")}:${(min).toString().padStart(2, "0")} am`
8+
return `${(hours + 12).toString().padStart(2, "0")}:${min.toString().padStart(2, "0")} am`;
109
} else if (hours > 12) {
11-
return `${(hours - 12).toString().padStart(2, "0")}:${(min).toString().padStart(2, "0")} pm`
12-
};
13-
return `${time} am`;
10+
return `${(hours - 12).toString().padStart(2, "0")}:${min.toString().padStart(2, "0")} pm`;
1411
}
12+
return `${time} am`;
13+
}
1514

16-
export {formatAs12HourClock};
17-
18-
15+
export { formatAs12HourClock };
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
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");
11-
assert.equal(formatAs12HourClock("01:00"), "01:00 am");
9+
test("can correctly convert morning time", function () {
10+
assert.equal(formatAs12HourClock("08:00"), "08:00 am");
11+
assert.equal(formatAs12HourClock("01:00"), "01:00 am");
1212
});
1313

14-
test("can correctly convert time with minutes for am", function(){
15-
assert.equal(formatAs12HourClock("08:35"), "08:35 am");
14+
test("can correctly convert time with minutes for am", function () {
15+
assert.equal(formatAs12HourClock("08:35"), "08:35 am");
1616
});
1717

18-
test("can correctly convert time with minutes for pm", function(){
19-
assert.equal(formatAs12HourClock("18:35"), "06:35 pm");
18+
test("can correctly convert time with minutes for pm", function () {
19+
assert.equal(formatAs12HourClock("18:35"), "06:35 pm");
2020
});
2121

22-
test("can correctly convert time with minutes with 0 pad such as 12:04", function(){
23-
assert.equal(formatAs12HourClock("13:04"), "01:04 pm");
22+
test("can correctly convert time with minutes with 0 pad such as 12:04", function () {
23+
assert.equal(formatAs12HourClock("13:04"), "01:04 pm");
2424
});
2525

26-
test("can correctly convert time with hour being 00 to show as 12 am", function(){
27-
assert.equal(formatAs12HourClock("00:00"), "12:00 am");
28-
assert.equal(formatAs12HourClock("00:30"), "12:30 am");
26+
test("can correctly convert time with hour being 00 to show as 12 am", function () {
27+
assert.equal(formatAs12HourClock("00:00"), "12:00 am");
28+
assert.equal(formatAs12HourClock("00:30"), "12:30 am");
2929
});
3030

31-
test("can correctly convert time with just after midnight to still show 12 am with minutes added", function(){
32-
assert.equal(formatAs12HourClock("00:01"), "12:01 am");
33-
});
31+
test("can correctly convert time with just after midnight to still show 12 am with minutes added", function () {
32+
assert.equal(formatAs12HourClock("00:01"), "12:01 am");
33+
});

0 commit comments

Comments
 (0)