From e5c80868f8e8893d467c92775df0473930bd0bf8 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Thu, 1 Oct 2026 00:49:24 +0100 Subject: [PATCH 1/8] Testing and adding in code: Added in time with minutes for am and pm --- format-clock-edge-cases/timeConverter.js | 11 ++++++++++- format-clock-edge-cases/timeConverter.test.js | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 310c07bd9..2df317d51 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -1,11 +1,20 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); + const min = Number(time.slice(-2)); +// if (hours > 12) { +// return `${hours - 12}:${min} pm`; +// } +// return `${time} am`; +// } if (hours > 12) { - return `${hours - 12}:00 pm`; + return `${(hours - 12).toString().padStart(2, "0")}:${(min).toString().padStart(2, "0")} pm`; } return `${time} am`; } export {formatAs12HourClock}; + +console.log(formatAs12HourClock("18:02")); + diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 88f2af094..a91fdb175 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -9,3 +9,11 @@ test("correctly convert time after 12:00", function(){ test("can correctly convert morning time", function() { assert.equal(formatAs12HourClock("08:00"), "08:00 am"); }); + +test("can correctly convert time with minutes for am", function(){ + assert.equal(formatAs12HourClock("08:35"), "08:35 am"); +}); + +test("can correctly convert time with minutes for pm", function(){ + assert.equal(formatAs12HourClock("18:35"), "06:35 pm"); +}); \ No newline at end of file From 1f0220a04eec3edbaef66a75e2d4849d3c4ca7ea Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Thu, 1 Oct 2026 01:03:45 +0100 Subject: [PATCH 2/8] added test for ensuring pad of 0 for single digit min --- format-clock-edge-cases/timeConverter.js | 11 ++++++----- format-clock-edge-cases/timeConverter.test.js | 4 ++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 2df317d51..b19621482 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -8,13 +8,14 @@ function formatAs12HourClock(time) { // } // return `${time} am`; // } - if (hours > 12) { - return `${(hours - 12).toString().padStart(2, "0")}:${(min).toString().padStart(2, "0")} pm`; - } + if (hours === 12) { + return `${time} pm` + } else if (hours > 12) { + return `${(hours - 12).toString().padStart(2, "0")}:${(min).toString().padStart(2, "0")} pm` + }; return `${time} am`; -} + } export {formatAs12HourClock}; -console.log(formatAs12HourClock("18:02")); diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index a91fdb175..b41dc3d2a 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -16,4 +16,8 @@ test("can correctly convert time with minutes for am", function(){ test("can correctly convert time with minutes for pm", function(){ assert.equal(formatAs12HourClock("18:35"), "06:35 pm"); +}); + +test("can correctly convert time with minutes with 0 pad such as 12:04", function(){ + assert.equal(formatAs12HourClock("13:04"), "01:04 pm"); }); \ No newline at end of file From f85f16691003b1121df387bd2006bdc1846a37fd Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Mon, 5 Oct 2026 14:48:36 +0100 Subject: [PATCH 3/8] deleted commented out code from lines 6-10 --- format-clock-edge-cases/timeConverter.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index b19621482..2ef9538fb 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -3,11 +3,6 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); const min = Number(time.slice(-2)); -// if (hours > 12) { -// return `${hours - 12}:${min} pm`; -// } -// return `${time} am`; -// } if (hours === 12) { return `${time} pm` } else if (hours > 12) { From 77d1ade2dfcd5d597d435a7fbe4dad2eb52e6ead Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Mon, 5 Oct 2026 15:01:16 +0100 Subject: [PATCH 4/8] Added in special hour of 00 to testing and adjust code. --- format-clock-edge-cases/timeConverter.js | 2 ++ format-clock-edge-cases/timeConverter.test.js | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index 2ef9538fb..e5f5aff44 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -5,6 +5,8 @@ function formatAs12HourClock(time) { if (hours === 12) { return `${time} pm` + } else if (hours === 0) { + return `${(hours + 12).toString().padStart(2, "0")}:${(min).toString().padStart(2, "0")} am` } else if (hours > 12) { return `${(hours - 12).toString().padStart(2, "0")}:${(min).toString().padStart(2, "0")} pm` }; diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index b41dc3d2a..fff781bee 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -8,6 +8,7 @@ test("correctly convert time after 12:00", function(){ test("can correctly convert morning time", function() { assert.equal(formatAs12HourClock("08:00"), "08:00 am"); + assert.equal(formatAs12HourClock("01:00"), "01:00 am"); }); test("can correctly convert time with minutes for am", function(){ @@ -20,4 +21,9 @@ test("can correctly convert time with minutes for pm", function(){ test("can correctly convert time with minutes with 0 pad such as 12:04", function(){ assert.equal(formatAs12HourClock("13:04"), "01:04 pm"); +}); + +test("can correctly convert time with hour being 00 to show as 12 am", function(){ + assert.equal(formatAs12HourClock("00:00"), "12:00 am"); + assert.equal(formatAs12HourClock("00:30"), "12:30 am"); }); \ No newline at end of file From 158eba2a827a43f6bf5be07e9adee71322ba8616 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Mon, 5 Oct 2026 15:06:23 +0100 Subject: [PATCH 5/8] Added extra test for 12:01 am --- format-clock-edge-cases/timeConverter.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index fff781bee..7fab536b7 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -26,4 +26,8 @@ test("can correctly convert time with minutes with 0 pad such as 12:04", functio test("can correctly convert time with hour being 00 to show as 12 am", function(){ assert.equal(formatAs12HourClock("00:00"), "12:00 am"); assert.equal(formatAs12HourClock("00:30"), "12:30 am"); +}); + +test("can correctly convert time with just after midnight to still show 12 am with minutes added", function(){ + assert.equal(formatAs12HourClock("00:01"), "12:01 am"); }); \ No newline at end of file From cf1ca72727eeca107665191201895e5c25b7b040 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Mon, 5 Oct 2026 15:32:22 +0100 Subject: [PATCH 6/8] Ensured extensions are added correctly and formatted document --- format-clock-edge-cases/timeConverter.js | 15 ++++---- format-clock-edge-cases/timeConverter.test.js | 36 +++++++++---------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/format-clock-edge-cases/timeConverter.js b/format-clock-edge-cases/timeConverter.js index e5f5aff44..c77cf5a17 100644 --- a/format-clock-edge-cases/timeConverter.js +++ b/format-clock-edge-cases/timeConverter.js @@ -1,18 +1,15 @@ function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); const min = Number(time.slice(-2)); if (hours === 12) { - return `${time} pm` + return `${time} pm`; } else if (hours === 0) { - return `${(hours + 12).toString().padStart(2, "0")}:${(min).toString().padStart(2, "0")} am` + return `${(hours + 12).toString().padStart(2, "0")}:${min.toString().padStart(2, "0")} am`; } else if (hours > 12) { - return `${(hours - 12).toString().padStart(2, "0")}:${(min).toString().padStart(2, "0")} pm` - }; - return `${time} am`; + return `${(hours - 12).toString().padStart(2, "0")}:${min.toString().padStart(2, "0")} pm`; } + return `${time} am`; +} -export {formatAs12HourClock}; - - +export { formatAs12HourClock }; diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 7fab536b7..8951fc6ac 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -1,33 +1,33 @@ -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"); - assert.equal(formatAs12HourClock("01:00"), "01:00 am"); +test("can correctly convert morning time", function () { + assert.equal(formatAs12HourClock("08:00"), "08:00 am"); + assert.equal(formatAs12HourClock("01:00"), "01:00 am"); }); -test("can correctly convert time with minutes for am", function(){ - assert.equal(formatAs12HourClock("08:35"), "08:35 am"); +test("can correctly convert time with minutes for am", function () { + assert.equal(formatAs12HourClock("08:35"), "08:35 am"); }); -test("can correctly convert time with minutes for pm", function(){ - assert.equal(formatAs12HourClock("18:35"), "06:35 pm"); +test("can correctly convert time with minutes for pm", function () { + assert.equal(formatAs12HourClock("18:35"), "06:35 pm"); }); -test("can correctly convert time with minutes with 0 pad such as 12:04", function(){ - assert.equal(formatAs12HourClock("13:04"), "01:04 pm"); +test("can correctly convert time with minutes with 0 pad such as 12:04", function () { + assert.equal(formatAs12HourClock("13:04"), "01:04 pm"); }); -test("can correctly convert time with hour being 00 to show as 12 am", function(){ - assert.equal(formatAs12HourClock("00:00"), "12:00 am"); - assert.equal(formatAs12HourClock("00:30"), "12:30 am"); +test("can correctly convert time with hour being 00 to show as 12 am", function () { + assert.equal(formatAs12HourClock("00:00"), "12:00 am"); + assert.equal(formatAs12HourClock("00:30"), "12:30 am"); }); -test("can correctly convert time with just after midnight to still show 12 am with minutes added", function(){ - assert.equal(formatAs12HourClock("00:01"), "12:01 am"); -}); \ No newline at end of file +test("can correctly convert time with just after midnight to still show 12 am with minutes added", function () { + assert.equal(formatAs12HourClock("00:01"), "12:01 am"); +}); From b56500c687f64005beb9afb4a0b92b6b2de2d460 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Tue, 6 Oct 2026 02:28:37 +0100 Subject: [PATCH 7/8] Added 5 more tests as requested. --- format-clock-edge-cases/timeConverter.test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 8951fc6ac..6adc39097 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -31,3 +31,19 @@ test("can correctly convert time with hour being 00 to show as 12 am", function test("can correctly convert time with just after midnight to still show 12 am with minutes added", function () { assert.equal(formatAs12HourClock("00:01"), "12:01 am"); }); + +test("last minute before 12 pm", function () { + assert.equal(formatAs12HourClock("11:59"), "11:59 am"); +}); +test("noon is 12 pm", function () { + assert.equal(formatAs12HourClock("12:00"), "12:00 pm"); +}); +test("first minute after noon", function () { + assert.equal(formatAs12HourClock("12:01"), "12:01 pm"); +}); +test("first hour after noon is 1 pm", function () { + assert.equal(formatAs12HourClock("13:00"), "01:00 pm"); +}); +test("last minute before midnight", function () { + assert.equal(formatAs12HourClock("23:59"), "11:59 pm"); +}); From 2fc03a94e3fa9457b3bd6721dc33dee292cb7fa6 Mon Sep 17 00:00:00 2001 From: HM-127BTY Date: Tue, 6 Oct 2026 02:32:21 +0100 Subject: [PATCH 8/8] fixed example in test to match the test itself. --- format-clock-edge-cases/timeConverter.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/format-clock-edge-cases/timeConverter.test.js b/format-clock-edge-cases/timeConverter.test.js index 6adc39097..916f14353 100644 --- a/format-clock-edge-cases/timeConverter.test.js +++ b/format-clock-edge-cases/timeConverter.test.js @@ -19,7 +19,7 @@ test("can correctly convert time with minutes for pm", function () { assert.equal(formatAs12HourClock("18:35"), "06:35 pm"); }); -test("can correctly convert time with minutes with 0 pad such as 12:04", function () { +test("can correctly convert time with minutes with 0 pad such as 13:04", function () { assert.equal(formatAs12HourClock("13:04"), "01:04 pm"); });