Skip to content

London | 26-ITP-Sep | Sakiya Mayow | Sprint 1 | Structuring and Testing Data - #1639

Open
zakiaao-tech wants to merge 4 commits into
CodeYourFuture:mainfrom
zakiaao-tech:testing-time-converting
Open

zakiaao-tech wants to merge 4 commits into
CodeYourFuture:mainfrom
zakiaao-tech:testing-time-converting

Conversation

@zakiaao-tech

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

In this task I added an if statement because when testing the code I noticed that for any hours < 10 is a single digit number but we need double digits and added 0 where it was supposed to go. I then tested a few edge cases and fixed the function according to the mistakes and failed tests.

@zakiaao-tech zakiaao-tech added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 3, 2026

@cjyuan cjyuan 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 test misses several cases.

You should update your test first before revising your function implementation.

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.

It seem your tests only cover two cases:

  • can correctly convert morning time
  • correctly convert time after 12:00

What about the boundary cases?

Could the function correctly handle the minute in the time? For examples, 00:34, 23:59?

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.

23:59 is tested now. 00:34 isn't yet; it's in the list in step 1 of my overall comment.

@cjyuan cjyuan 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 4, 2026
@zakiaao-tech zakiaao-tech added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label 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.

Writing the tests first and then adding minutes to the function, as your last two commits show, was the right order. 23:59 and 12:01 both come out right now.

There's one bug left in the function, and a few tests to add that will show it to you. Here are the steps:

  1. Add a test for each of these times: "11:59", "00:00", "00:34", "12:00". Write each test in the same shape as yours. The first "..." is the time going in. The second "..." is what your function should give back, as a 12-hour clock would show it. Decide that yourself before you run anything, for example: what does a 12-hour clock show at 00:34?
    test("describe the time you are checking", function () {
      assert.equal(formatAs12HourClock("..."), "...");
    });
  2. Run the tests. Right click the format-clock-edge-cases folder in VS Code, choose Open in Integrated Terminal, and run node --test. The 11:59 test should fail and show you what your function really returns: 11:59: 59 am. That's good. It means the test has found a bug, and every time from 10:00 to 11:59 has it.
  3. Fix the bug. It's on timeConverter.js line 24 (see my comment there). Run node --test again until every test passes.
  4. Sort out the four tests on lines 13 to 27. See my comment on line 13.

When all of that is pushed and every test passes, it should be ready to mark Complete. Add the Needs Review label again once you've pushed.

return `0${hours}:${minutes} am`;
}

return `${time}: ${minutes} 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.

time holds the whole input, for example "10:30". So ${time} already includes the minutes, and : ${minutes} then adds them a second time, with a space in front. That's how you get 10:30: 30 am.

For 10:00 to 11:59 the hours already have two digits, so nothing needs changing about them. What does ${time} on its own give you, and is that all you need before am?

assert.equal(formatAs12HourClock("23:59"), "11:59 pm");
});

test("converts 12:01 to 12:01 ", function () {

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.

Bugs often hide at the exact point where something changes. 12:01 is the first minute after noon, so the last minute before noon, 11:59, is just as important. Your function gets 11:59 wrong at the moment, and a test for it would have shown you. Midnight (00:00) and noon (12:00) are the other two points where the clock changes, so they need a test each too.

assert.equal(formatAs12HourClock("08:00"), "08:00 am");
});

test("correctly convert time after 12:00 ", function () {

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.

These four tests all have the same name, "correctly convert time after 12:00". If one of them failed, the output wouldn't tell you which time broke. They also all check a whole hour between 2pm and 9pm, so they all test the same thing.

Keep one of them, and give it a name that says the time it checks, for example "converts 14:00 to 02:00 pm". Delete the other three. Your new tests from step 1 of my overall comment test far more.

@abdishakoor-dev abdishakoor-dev removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 6, 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.

3 participants