Skip to content

London | 26-ITP-Sep | Mahir Shah | Sprint 1 | Format clock edge cases - #1653

Open
MahirShah300 wants to merge 3 commits into
CodeYourFuture:mainfrom
MahirShah300:format-clock-edge-cases
Open

MahirShah300 wants to merge 3 commits into
CodeYourFuture:mainfrom
MahirShah300:format-clock-edge-cases

Conversation

@MahirShah300

Copy link
Copy Markdown

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

Made changes to the code to fix bugs, and wrote tests for different inputs

@MahirShah300 MahirShah300 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 5, 2026
Comment on lines +85 to +88
test("can correctly convert time after using one digit for hour and . for time separator", function () {
assert.equal(formatAs12HourClock("3.30"), "03:30 am");
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is the same test as in line 81

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.

I have removed the accidental extra test

});

test("can correctly convert time after 12 with minutes that are not 00", function () {
assert.equal(formatAs12HourClock("23:46"), "23:46 pm");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This tests fails for me. Can you explain why?

AssertionError [ERR_ASSERTION]: '11:46 pm' == '23:46 pm'
      at TestContext.<anonymous> (Module-Structuring-and-Testing-Data/format-clock-edge-cases/timeConverter.test.js:14:10)
      at Test.runInAsyncScope (node:async_hooks:228:14)
      at Test.run (node:internal/test_runner/test:1118:25)
      at Test.processPendingSubtests (node:internal/test_runner/test:787:18)
      at Test.postRun (node:internal/test_runner/test:1247:19)
      at Test.run (node:internal/test_runner/test:1175:12)
      at async Test.processPendingSubtests (node:internal/test_runner/test:787:7) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: '11:46 pm',
    expected: '23:46 pm',
    operator: '==',
    diff: 'simple'
  }

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.

The problem is that in my test I incorrectly put the 24 hour time 23:46 pm instead of what should be 11:46 pm

});

test("can correctly convert time using . as time separator", function () {
assert.equal(formatAs12HourClock("01.30"), "1:30 am");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This tests fails for me. Can you explain why?

actual: '01:30 am',
expected: '1:30 am',

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.

Because in test I was meant to say the expected value is "01:30 am", I forgot to set the hour to 2 significant figures


let colonPeriodIndex = 0;
if (time.indexOf(":") === -1) {
colonPeriodIndex = time.indexOf(".");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What does this line do and why is it needed?

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.

In this line I get the index of the time separator. First I initialise colonPeriodIndex to 0, then I check if the ":" separator is not in the input string, and then set colonPeriodIndex to the index of "." . It's because I chose to accept "." as a valid separator.

@Luro91 Luro91 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 6, 2026
@MahirShah300 MahirShah300 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 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants