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
c3cc796
refactor: update formatAs12HourClock function to improve time parsing…
moses77-boop Oct 3, 2026
b03e0fb
refactor: update test syntax to use arrow functions for consistency
moses77-boop Oct 3, 2026
05e8ef3
fix: ensure formatAs12HourClock function exports correctly
moses77-boop Oct 3, 2026
1544b38
test: add test case for converting midnight time
moses77-boop Oct 3, 2026
8230a0e
refactor: improve time conversion logic and enhance test cases for cl…
moses77-boop Oct 3, 2026
ead95df
fix: correct return statement in formatAs12HourClock function for acc…
moses77-boop Oct 3, 2026
19e10f5
test: add test case for converting the last minute before noon
moses77-boop Oct 3, 2026
15938a2
test: add test case for converting exact noon to pm
moses77-boop Oct 3, 2026
8acdeaa
test: add test case for converting time just after noon
moses77-boop Oct 3, 2026
a7d1115
fix: add missing newline at end of timeConverter.test.js
moses77-boop Oct 3, 2026
ee8f85b
fix: remove space before am/pm in time formatting and clean up test c…
moses77-boop Oct 3, 2026
f93cd35
fix: remove space before period in time formatting
moses77-boop Oct 3, 2026
59863c5
test: add test case for converting late evening hour
moses77-boop Oct 3, 2026
c6ed571
test: add test case for converting last minute of the day
moses77-boop Oct 3, 2026
ced1c53
fix: correct expected output for first afternoon hour test case
moses77-boop Oct 3, 2026
9f0876f
test: add test case for preserving minutes with leading zero
moses77-boop Oct 3, 2026
03c860b
test: update console log to test formatting for 8:00 AM
moses77-boop Oct 3, 2026
42d563c
test: add test case for preserving non-zero minutes
moses77-boop Oct 3, 2026
91ccb0c
test: update console log to test formatting for 8:40 AM
moses77-boop Oct 3, 2026
472364d
Remove commented-out code from time formatting function
moses77-boop Oct 4, 2026
5b48a96
Remove console log from time formatting function
moses77-boop Oct 4, 2026
8a74015
Add jsconfig.json for TypeScript configuration
moses77-boop Oct 4, 2026
27919c8
Format code and improve readability
moses77-boop Oct 4, 2026
fa688b1
Simplify period determination and improve formatting
moses77-boop Oct 5, 2026
5d58269
Refactor display hour calculation for 12-hour clock format
moses77-boop Oct 5, 2026
f9fac2a
Remove jsconfig.json and clean up package.json by deleting devDepende…
moses77-boop Oct 5, 2026
aba0771
Refactor folders to match main
moses77-boop Oct 5, 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
13 changes: 6 additions & 7 deletions format-clock-edge-cases/timeConverter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
function formatAs12HourClock(time) {
const [hourPart, minutePart] = time.split(":");
const hours = Number(hourPart);

const hours = Number(time.slice(0, 2));
const period = hours < 12 ? "am" : "pm";

if (hours > 12) {
return `${hours - 12}:00 pm`;
}
return `${time} am`;
const displayHour = hours % 12 || 12;
return `${displayHour}:${minutePart}${period}`;
}

export {formatAs12HourClock};
export { formatAs12HourClock };
40 changes: 35 additions & 5 deletions format-clock-edge-cases/timeConverter.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
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", () => {
assert.equal(formatAs12HourClock("23:00"), "11:00pm");
});

test("can correctly convert morning time", function() {
assert.equal(formatAs12HourClock("08:00"), "08:00 am");
test("converts a single-digit morning hour and drops leading zero", () => {
assert.equal(formatAs12HourClock("08:00"), "8:00am");
});
test("converts exactly to midnight", () => {
assert.equal(formatAs12HourClock("00:00"), "12:00am");
});
test("converts time just after midnight", () => {
assert.equal(formatAs12HourClock("00:30"), "12:30am");
});
test("converts the last minute before noon", () => {
assert.equal(formatAs12HourClock("11:59"), "11:59am");
});
test("converts exact noon to pm", () => {
assert.equal(formatAs12HourClock("12:00"), "12:00pm");
});
test("convert time just after noon", () => {
assert.equal(formatAs12HourClock("12:30"), "12:30pm");
});
test("converts the first afternoon hour", () => {
assert.equal(formatAs12HourClock("13:00"), "1:00pm");
});
test("converts late evening hour", () => {
assert.equal(formatAs12HourClock("23:00"), "11:00pm");
});
test("converts last minute of the day", () => {
assert.equal(formatAs12HourClock("23:59"), "11:59pm");
});
test("preserves minutes with leading zero", () => {
assert.equal(formatAs12HourClock("09:05"), "9:05am");
});
test("preserves non-zero minutes", () => {
assert.equal(formatAs12HourClock("14:45"), "2:45pm");
});
Loading