Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f66d02c
added a test for 24:00 and test failed
MaharitB Oct 4, 2026
3ce6795
fixed a bug to return12:00 when time given 24:00
MaharitB Oct 4, 2026
0ec1be7
fixed bug changed time ===24:00 and added am at line 4 and 5
MaharitB Oct 4, 2026
b54183b
addes test for converting midday 12:00 to 12:00 pm
MaharitB Oct 4, 2026
f1bf893
test failed . fixing the bug. added a code on line 7 that returns 12:…
MaharitB Oct 4, 2026
edf5168
added a test , to convert time with minute. test failed
MaharitB Oct 4, 2026
ab3e5fa
added a test that coverts time at the end of midnight 00:59. test fai…
MaharitB Oct 4, 2026
1d4f08b
added a code for converting with min and converting end of midninght
MaharitB Oct 4, 2026
ce0ae5f
just making sure there is no redundancy in the coding
MaharitB Oct 4, 2026
8baa8cb
run prettier for timeConverter.test.js
MaharitB Oct 4, 2026
cdcbc38
run prettier for timeConverter.js
MaharitB Oct 4, 2026
0d2d87c
changed the input in the function to be 00:00.and made some changes i…
MaharitB Oct 5, 2026
f0c87a6
made three lines in comment if the test works with out the three line…
MaharitB Oct 5, 2026
405d9b5
deleted three lines of code that were in a comment. test is success w…
MaharitB Oct 5, 2026
b1b6c72
changed the return ${mints}to 00, no test failed .kept the line
MaharitB Oct 5, 2026
b516b52
wrote a test for the first begning of noon.test success
MaharitB Oct 5, 2026
f81b432
fixed some errors on the test for begning of noon
MaharitB Oct 5, 2026
6a3dca5
put the time===12 line in a comment and run the test and it wa success
MaharitB Oct 5, 2026
355ec16
deleted the commented line of code .because test passed when run with…
MaharitB Oct 5, 2026
46fc4ac
made the const stringHours on a comments to test run a test .Test was…
MaharitB Oct 5, 2026
c8ec94b
deleted the line i commented and run prettier.
MaharitB Oct 5, 2026
90adf7b
wrote a test to convert time later than midday with minutes.test failed
MaharitB Oct 5, 2026
3710e74
change code based on the test made for 13:00 and greater with min..tw…
MaharitB Oct 5, 2026
cfb67ae
wrote a test to convert the last minute am to pm.test success.
MaharitB Oct 5, 2026
934dfc3
wrote a test that can convert last minute of the day .test success.
MaharitB Oct 5, 2026
cfd5727
run prettier and saved
MaharitB Oct 6, 2026
8f1d13f
run prettier and saved
MaharitB Oct 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions format-clock-edge-cases/timeConverter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
function formatAs12HourClock(time) {

const mints = time.slice(-2);
const hours = Number(time.slice(0, 2));

if (hours > 12) {
return `${hours - 12}:00 pm`;
if (hours == "00") {
return `12:${mints} am`;
}
if (hours === 12) {
return `${hours}:${mints} pm`;
}
if (hours > 12 && hours < 22) {
return `0${hours - 12}:${mints} pm`;
}
if (hours >= 22) {
return `${hours - 12}:${mints} pm`;
}
return `${time} am`;
}

export {formatAs12HourClock};
export { formatAs12HourClock };
38 changes: 33 additions & 5 deletions format-clock-edge-cases/timeConverter.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
import {formatAs12HourClock} from "./timeConverter.js";
import { formatAs12HourClock } from "./timeConverter.js";
import assert from "node:assert";
import test from "node:test";

test("correctly convert time after 12:00", function(){
assert.equal(formatAs12HourClock("23:00"), "11:00 pm");
test("correctly convert time after 12:00", function () {
assert.equal(formatAs12HourClock("23:00"), "11:00 pm");
});

test("can correctly convert morning time", function() {
assert.equal(formatAs12HourClock("08:00"), "08:00 am");
test("can correctly convert morning time", function () {
assert.equal(formatAs12HourClock("08:00"), "08:00 am");
});

test("can correctly convert midnight ", function () {
assert.equal(formatAs12HourClock("00:00"), "12:00 am");
});

test("can correctly convert midday ", function () {
assert.equal(formatAs12HourClock("12:00"), "12:00 pm");
});

test("can correctly convert time with minutes ", function () {
assert.equal(formatAs12HourClock("12:45"), "12:45 pm");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The starter dropped the minutes for afternoon times: "23:59" gave "11:00 pm". Try changing line 18 of timeConverter.js to return :00 instead of the minutes, and run your tests. Does any of them fail?

Bugs often hide at the exact point where something changes. What is the last minute before am turns into pm, and the last minute of the whole day? Each of those is worth its own test.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your 13:01 test catches this now for 1pm to 9pm. The last gap is after 10pm, see my new comment on line 15.

});

test("can correctly convert time the end of midnight", function () {
assert.equal(formatAs12HourClock("00:59"), "12:59 am");
});
test("can correctly convert time at the beginning of noon", function () {
assert.equal(formatAs12HourClock("12:01"), "12:01 pm");
});
test("can correctly convert time later than midday", function () {
assert.equal(formatAs12HourClock("13:01"), "01:01 pm");
});
test("can correctly convert time the last minute am turns pm ", function () {
assert.equal(formatAs12HourClock("11:59"), "11:59 am");
});
test("can correctly convert time last minute of the day", function () {
assert.equal(formatAs12HourClock("23:59"), "11:59 pm");
});
Loading