Solution#2691
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
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 YY → YY 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 YY → YYYY 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
| break; | ||
|
|
||
| case 'YY': | ||
| resultArray[i] = givenArray[yearIndex].slice(2); |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 YY → YY 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! ✨
No description provided.