formatDate#2680
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 correctness issue with the YY → YYYY conversion logic in src/formatDate.js, and this directly violates the task’s specified rule. The requirement states that two-digit years should map to 20YY when YY < 30 and to 19YY otherwise, but your implementation currently uses a cutoff of <= 26, which will incorrectly map 27, 28, and 29 (e.g., 29 becomes 1929 instead of 2029). This is a functional bug, not just a style preference, and it will produce wrong outputs for valid inputs described in the task, so it must be fixed before the solution can be considered complete. To address this, update the comparison where you expand YY to YYYY so that it explicitly checks Number(yy) < 30 (or an equivalent condition) and then chooses the correct century prefix accordingly. Aside from this issue, your separator handling, part reordering, and YYYY → YY conversion are all implemented clearly and align well with the task requirements. Once you adjust the cutoff to match the specification exactly, your solution should satisfy the functional requirements fully, and this will be a good, clean implementation of the date formatting logic.
✨ 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
| let fullYear = dateArr[years] || dateArr[year2]; | ||
|
|
||
| if (fullYear.length === 2) { | ||
| fullYear = Number(fullYear) <= 26 ? '20' + fullYear : '19' + fullYear; |
There was a problem hiding this comment.
The cutoff for expanding YY to YYYY should be < 30 according to the task description; using <= 26 will produce incorrect years for 27, 28, and 29 (e.g., 29 should map to 2029, not 1929). Consider updating the comparison to match YY < 30.
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 of the task and matches the specified behavior for all examples. The formatDate function correctly treats date, fromFormat, and toFormat as required parameters and uses the separators from each format to split and rejoin the parts, so changing separators works as intended. You successfully locate DD, MM, YYYY, and YY positions based on fromFormat and rebuild the result according to toFormat, which covers all required reordering scenarios. The year conversion logic between YYYY and YY is implemented exactly as specified, including the cutoff rule that uses 20YY when YY < 30 and 19YY otherwise, and it produces the correct outputs for all sample cases like 2020.02.18, 18.02.2020, 18/02/20, and 18.02.1997. You also correctly follow the constraint of not adding extra validation and assuming well-formed inputs, keeping the implementation focused and clear. Nice work bringing everything in line with the checklist; this is a solid, accurate implementation.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.