Skip to content

London | 26-ITP-Sep | Maharit Belai | Sprint 1 | Format clock edge cases - #1645

Open
MaharitB wants to merge 23 commits into
CodeYourFuture:mainfrom
MaharitB:format-clock-edge-cases
Open

MaharitB wants to merge 23 commits into
CodeYourFuture:mainfrom
MaharitB:format-clock-edge-cases

Conversation

@MaharitB

@MaharitB MaharitB commented Oct 4, 2026

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Task code

CYF-1197

Changelist

wrote a test for clock edge cases.

Questions

@github-actions

This comment has been minimized.

@MaharitB MaharitB added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 4, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 4, 2026
@MaharitB MaharitB changed the title London | 26-ITP-Sep | Maharit Belai | Sprint-1 | Format clock edge cases London | 26-ITP-Sep | Maharit Belai | Sprint 1 | Format clock edge cases Oct 4, 2026
@MaharitB MaharitB added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 4, 2026

@abdishakoor-dev abdishakoor-dev left a comment

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 commit history shows the process this task is about: write a test, see it fail, then fix the code. You also kept the two starter tests exactly as they were, and the function gives the right answer for every valid time I tried.

Two things before I can mark this Complete:

  1. The midnight test uses an input that isn't in the range the README asks for. See my comment on timeConverter.test.js line 14.
  2. One of the starter's bugs, and the edges where am changes to pm and back, have no test yet. See my comment on line 22.

The two comments on timeConverter.js are smaller and come out of the same idea: try deleting or changing a line, and see whether any test notices.

Add the Needs Review label again once you've pushed.

});

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

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.

On a 24-hour clock, does midnight show as 24:00 or 00:00? The clock in this task runs from 00:00 to 23:59, and the README only asks for valid inputs. Which input should this test use? Once you've changed it, do you still need lines 5 to 7 of timeConverter.js?

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.

Fixed now, and the 24:00 check has gone too. Good.

});

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.

if (time === "24:00") {
return `12:00 am`;
}
if (time === "12:00") {

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.

If you delete lines 8 to 10, which if would "12:00" reach next? Would it still give "12:00 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.

That's the one, deleted and the test still passes.

if (time === "12:00") {
return `12:00 pm`;
}
if (stringHours == "00") {

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.

Optional, not needed for Complete: line 14 checks hours with ===. Could line 11 check hours in the same way? If it did, would you still need stringHours on line 2?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good question! My initial thought was to compare string to a string thinking if I compare the number to a string it will give me false. Now that I read about it, I can compare the hour with == to the "00" and get the same answer. because in Java Script if you compare numeric with string, and if the sting can be changed to numeric value, the output can be true.

So I will make amends to the code based on this finding.

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.

Good reading, and removing stringHours made the function simpler. Nothing more needed here.

@abdishakoor-dev abdishakoor-dev added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 5, 2026
@MaharitB MaharitB added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Oct 5, 2026

@abdishakoor-dev abdishakoor-dev left a comment

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.

Good progress. Midnight and midday are both sorted, and the extra lines they needed are gone. Choosing 01:01 pm so afternoons match 08:00 am keeps the output consistent, nice.

You're very close. Two small things and this is Complete:

  1. Add two more tests, written the same way as your others:

    • "11:59" should give "11:59 am" (the last minute before am turns into pm)
    • "23:59" should give "11:59 pm" (the last minute of the day)

    My comment on timeConverter.js line 15 explains why the second one matters.

  2. Both files need formatting again. Open timeConverter.js, right click in the editor, choose Format Document, and save. Do the same for timeConverter.test.js. Then commit and push.

Once both are pushed, add the Needs Review label again and I'll mark it Complete.

return `0${hours - 12}:${mints} pm`;
}
if(hours>=22){
return `${hours-12}:${mints} 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.

In commit b1b6c72 you changed the minutes to 00, saw no test fail, and kept the line. That was the right experiment. When no test fails, it means a test is missing, not that the line is fine. A test that should have failed shows you where your tests have a gap.

The same gap is on this line now. If it returned :00 instead of the minutes, every test would still pass, because "23:00" is the only time you test after 10pm and its minutes are already 00. A "23:59" test closes that gap.

@abdishakoor-dev abdishakoor-dev added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants