-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Solution #2181
base: master
Are you sure you want to change the base?
Solution #2181
Conversation
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.
Thank you for your hard work on this Pull Request! 😊 While your implementation of the formatDate
function meets many of the task requirements, there are a couple of critical issues that need to be addressed before we can approve it:
-
Date Format Validation: The function currently does not validate whether the
date
string matches thefromFormat
. This could lead to incorrect conversions or errors. Adding validation to ensure the input date format matches the expected format would improve the robustness of your solution. -
Year Conversion Logic: The logic for converting 'YY' to 'YYYY' uses a fixed cutoff year of 30, which might not be suitable for all scenarios. Consider making this logic more flexible or configurable, or at least document the assumptions clearly so users are aware of this behavior.
Once these issues are resolved, your solution will be much stronger and ready for approval. Keep up the great work, and I look forward to seeing your improvements! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
src/formatDate.js
Outdated
if (dateSet.YY < 30) { | ||
newFormat.push('20' + dateSet.YY); | ||
} else { | ||
newFormat.push('19' + dateSet.YY); |
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 logic for converting 'YY' to 'YYYY' is based on a fixed cutoff year of 30, which may not be suitable for all use cases. Consider making this logic more flexible or configurable, or clarify the assumptions in the documentation.
src/formatDate.js
Outdated
if (dateSet[key]) { | ||
newFormat.push(dateSet[key]); | ||
} else if (key === 'YY') { | ||
newFormat.push(dateSet.YYYY.slice(2)); | ||
} else if (key === 'YYYY') { | ||
if (dateSet.YY < 30) { | ||
newFormat.push('20' + dateSet.YY); | ||
} else { | ||
newFormat.push('19' + dateSet.YY); | ||
} | ||
} |
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 function does not handle cases where the date format specified in fromFormat
does not match the actual format of the date
string. Consider adding validation to ensure the date
string matches the fromFormat
before processing.
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.
Review Summary
Great job on implementing the formatDate
function! 🎉 Your solution meets the task requirements and constraints, and the logic for converting 'YY' to 'YYYY' is correctly implemented. However, there are a couple of critical issues that need attention:
-
Date Format Validation: Although the task specifies that input validation isn't necessary, adding a check to ensure the
date
string matches thefromFormat
would enhance the robustness of your code and prevent potential errors. -
Year Conversion Logic: The current logic assumes that
dateSet.YY
is always present, which may not be the case if 'YY' isn't included in the input format. Adding checks for such scenarios will make your solution more reliable.
Despite these issues, the decision to approve your pull request is made to help you progress in your learning journey. Please review the comments and address these critical issues in future iterations to improve your code quality. Keep up the good work and continue learning from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
@@ -7,8 +7,33 @@ | |||
* | |||
* @returns {string} | |||
*/ | |||
function formatDate(date, fromFormat, toFormat) { | |||
// write code here | |||
function formatDate(date, fromFormat, toFormat, cutoffYear = 30) { |
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.
Consider adding validation to ensure that the date
string matches the fromFormat
. This will help prevent incorrect conversions or errors if the input format is not as expected.
if (dateSet.YY < cutoffYear) { | ||
newFormat.push('20' + dateSet.YY); | ||
} else { | ||
newFormat.push('19' + dateSet.YY); |
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 logic assumes that dateSet.YY
is always available, which might not be the case if the input format does not include 'YY'. Consider adding checks to handle scenarios where 'YY' is not part of the fromFormat
.
No description provided.