Skip to content

Solution#2691

Open
polina3107 wants to merge 2 commits into
mate-academy:masterfrom
polina3107:develop
Open

Solution#2691
polina3107 wants to merge 2 commits into
mate-academy:masterfrom
polina3107:develop

Conversation

@polina3107

Copy link
Copy Markdown

No description provided.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

I am requesting changes because there is a critical functional bug in the year conversion logic that breaks a valid, required case. Specifically, in src/formatDate.js where you handle YY output (around the branch that does givenArray[yearIndex].slice(2)), you always slice off the first two digits, assuming a 4-digit year; when the source format is already YY, givenArray[yearIndex] has only two characters, so slice(2) returns an empty string, making YYYY produce an incorrect year. This violates the requirement that the function correctly converts and preserves years for all valid combinations of fromFormat and toFormat, including YY inputs when toFormat is also YY. To fix this, add a check on the length of the year string: if it’s already 2 digits, return it unchanged; only call slice(2) when it’s 4 digits. Aside from this bug, your overall approach to parsing fromFormat, handling separators, and applying the 19xx/20xx rule for YYYYYY is solid and aligns well with the task. Once you address this conditional slicing issue, your solution should fully satisfy the functional requirements.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/formatDate.js Outdated
break;

case 'YY':
resultArray[i] = givenArray[yearIndex].slice(2);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here you always do slice(2) to produce YY. This is correct for a 4-digit YYYY input, but if the source format uses YY, givenArray[yearIndex] already has 2 digits and slice(2) will return an empty string. Consider checking the length of the year string and returning it unchanged when it is already 2 digits, only slicing when it is 4 digits.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

Your solution is approved because it now fully meets the functional requirements and handles all specified date transformations correctly. The formatDate function properly detects and switches separators, reorders date parts based on the positions of YYYY/YY, MM, and DD, and assumes correctly formatted inputs as required. The year conversion logic is implemented accurately: 4-digit years are reduced to the last two digits when converting to YY, and 2-digit years are expanded to 4 digits using the 20/19 rule when converting to YYYY. This also correctly preserves 2-digit years in YYYY cases without unnecessary slicing, which was a previously highlighted requirement. I don’t see any critical or blocking issues remaining, and the code is concise and focused on the task. Nicely done addressing the earlier bug and aligning strictly with the checklist and specification.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants