Repository navigation
London | 26-ITP-Sep | Maharit Belai | Sprint 1 | Format clock edge cases #1645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MaharitB
wants to merge
27
commits into
CodeYourFuture:main
Choose a base branch
from
MaharitB:format-clock-edge-cases
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
f66d02c
added a test for 24:00 and test failed
MaharitB 3ce6795
fixed a bug to return12:00 when time given 24:00
MaharitB 0ec1be7
fixed bug changed time ===24:00 and added am at line 4 and 5
MaharitB b54183b
addes test for converting midday 12:00 to 12:00 pm
MaharitB f1bf893
test failed . fixing the bug. added a code on line 7 that returns 12:…
MaharitB edf5168
added a test , to convert time with minute. test failed
MaharitB ab3e5fa
added a test that coverts time at the end of midnight 00:59. test fai…
MaharitB 1d4f08b
added a code for converting with min and converting end of midninght
MaharitB ce0ae5f
just making sure there is no redundancy in the coding
MaharitB 8baa8cb
run prettier for timeConverter.test.js
MaharitB cdcbc38
run prettier for timeConverter.js
MaharitB 0d2d87c
changed the input in the function to be 00:00.and made some changes i…
MaharitB f0c87a6
made three lines in comment if the test works with out the three line…
MaharitB 405d9b5
deleted three lines of code that were in a comment. test is success w…
MaharitB b1b6c72
changed the return ${mints}to 00, no test failed .kept the line
MaharitB b516b52
wrote a test for the first begning of noon.test success
MaharitB f81b432
fixed some errors on the test for begning of noon
MaharitB 6a3dca5
put the time===12 line in a comment and run the test and it wa success
MaharitB 355ec16
deleted the commented line of code .because test passed when run with…
MaharitB 46fc4ac
made the const stringHours on a comments to test run a test .Test was…
MaharitB c8ec94b
deleted the line i commented and run prettier.
MaharitB 90adf7b
wrote a test to convert time later than midday with minutes.test failed
MaharitB 3710e74
change code based on the test made for 13:00 and greater with min..tw…
MaharitB cfb67ae
wrote a test to convert the last minute am to pm.test success.
MaharitB 934dfc3
wrote a test that can convert last minute of the day .test success.
MaharitB cfd5727
run prettier and saved
MaharitB 8f1d13f
run prettier and saved
MaharitB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,20 @@ | ||
| function formatAs12HourClock(time) { | ||
|
|
||
| const mints = time.slice(-2); | ||
| const hours = Number(time.slice(0, 2)); | ||
|
|
||
| if (hours > 12) { | ||
| return `${hours - 12}:00 pm`; | ||
| if (hours == "00") { | ||
| return `12:${mints} am`; | ||
| } | ||
| if (hours === 12) { | ||
| return `${hours}:${mints} pm`; | ||
| } | ||
| if (hours > 12 && hours < 22) { | ||
| return `0${hours - 12}:${mints} pm`; | ||
| } | ||
| if (hours >= 22) { | ||
| return `${hours - 12}:${mints} pm`; | ||
| } | ||
| return `${time} am`; | ||
| } | ||
|
|
||
| export {formatAs12HourClock}; | ||
| export { formatAs12HourClock }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,39 @@ | ||
| 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"); | ||
| test("can correctly convert morning time", function () { | ||
| assert.equal(formatAs12HourClock("08:00"), "08:00 am"); | ||
| }); | ||
|
|
||
| test("can correctly convert midnight ", function () { | ||
| assert.equal(formatAs12HourClock("00:00"), "12:00 am"); | ||
| }); | ||
|
|
||
| test("can correctly convert midday ", function () { | ||
| assert.equal(formatAs12HourClock("12:00"), "12:00 pm"); | ||
| }); | ||
|
|
||
| test("can correctly convert time with minutes ", function () { | ||
| assert.equal(formatAs12HourClock("12:45"), "12:45 pm"); | ||
| }); | ||
|
|
||
| test("can correctly convert time the end of midnight", function () { | ||
| assert.equal(formatAs12HourClock("00:59"), "12:59 am"); | ||
| }); | ||
| test("can correctly convert time at the beginning of noon", function () { | ||
| assert.equal(formatAs12HourClock("12:01"), "12:01 pm"); | ||
| }); | ||
| test("can correctly convert time later than midday", function () { | ||
| assert.equal(formatAs12HourClock("13:01"), "01:01 pm"); | ||
| }); | ||
| test("can correctly convert time the last minute am turns pm ", function () { | ||
| assert.equal(formatAs12HourClock("11:59"), "11:59 am"); | ||
| }); | ||
| test("can correctly convert time last minute of the day", function () { | ||
| assert.equal(formatAs12HourClock("23:59"), "11:59 pm"); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 oftimeConverter.jsto return:00instead 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your
13:01test catches this now for 1pm to 9pm. The last gap is after 10pm, see my new comment on line 15.