Skip to content

Commit 92fc81c

Browse files
cyfcyf
authored andcommitted
format code for midnight(00:00)
1 parent 29ef74a commit 92fc81c

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

Lines changed: 5 additions & 4 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));
4-
3+
if (hours === 0) {
4+
return `${hours + 12}${time.slice(2, 5)} am`;
5+
}
56
if (hours > 12) {
6-
return `${hours - 12}:00 pm`;
7+
return `${hours - 12}${time.slice(2, 5)} pm`;
78
}
89
return `${time} am`;
910
}
1011

11-
export {formatAs12HourClock};
12+
export { formatAs12HourClock };
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
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");
11+
});
12+
13+
test("can correctly convert midnight time", function () {
14+
assert.equal(formatAs12HourClock("00:00"), "12:00 am");
1115
});

0 commit comments

Comments
 (0)