Skip to content

Commit ac13b95

Browse files
committed
style: format code for consistency and readability in time conversion functions and tests
1 parent 8d645cd commit ac13b95

2 files changed

Lines changed: 22 additions & 20 deletions

File tree

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

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

65
if (hours > 12) {
76
const convertedHours = hours - 12;
87
// Add leading zero if convertedHours is a single digit
9-
const formattedHours = convertedHours < 10 ? `0${convertedHours}` : convertedHours;
8+
const formattedHours =
9+
convertedHours < 10 ? `0${convertedHours}` : `${convertedHours}`;
1010
return `${formattedHours}:${minutes} pm`;
1111
}
12-
//handling noon.
12+
//handling noon.
1313
if (hours === 12) {
1414
return `12:${minutes} pm`;
1515
}
@@ -22,4 +22,4 @@ function formatAs12HourClock(time) {
2222
return `${time} am`;
2323
}
2424

25-
export {formatAs12HourClock};
25+
export { formatAs12HourClock };
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
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
});
1212

13-
14-
test("correctly convert midnight", function() {
15-
assert.equal(formatAs12HourClock("00:00"), "12:00 am");
13+
test("correctly convert midnight", function () {
14+
assert.equal(formatAs12HourClock("00:00"), "12:00 am");
1615
});
1716

18-
test("correctly convert noon", function() {
19-
assert.equal(formatAs12HourClock("12:00"), "12:00 pm");
17+
test("correctly convert noon", function () {
18+
assert.equal(formatAs12HourClock("12:00"), "12:00 pm");
2019
});
2120

22-
test("correctly convert single digit hour in the morning", function() {
23-
assert.equal(formatAs12HourClock("01:30"), "01:30 am");
21+
test("correctly convert single digit hour in the morning", function () {
22+
assert.equal(formatAs12HourClock("01:30"), "01:30 am");
2423
});
2524

26-
test("correctly convert single digit hour in the afternoon", function() {
27-
assert.equal(formatAs12HourClock("13:45"), "01:45 pm");
25+
test("correctly convert single digit hour in the afternoon", function () {
26+
assert.equal(formatAs12HourClock("13:45"), "01:45 pm");
2827
});
2928

30-
test("correctly convert time with leading zeros", function() {
31-
assert.equal(formatAs12HourClock("09:05"), "09:05 am");
29+
test("correctly convert time with leading zeros", function () {
30+
assert.equal(formatAs12HourClock("09:05"), "09:05 am");
3231
});
3332

33+
test("correctly convert double digit hour in the afternoon", function () {
34+
assert.equal(formatAs12HourClock("15:20"), "03:20 pm");
35+
});

0 commit comments

Comments
 (0)