Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Solution #2181

wants to merge 2 commits into from

Conversation

Bankir4ik87
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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:

  1. Date Format Validation: The function currently does not validate whether the date string matches the fromFormat. 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.

  2. 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.

Comment on lines 28 to 31
if (dateSet.YY < 30) {
newFormat.push('20' + dateSet.YY);
} else {
newFormat.push('19' + dateSet.YY);

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.

Comment on lines 23 to 33
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);
}
}

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.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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:

  1. Date Format Validation: Although the task specifies that input validation isn't necessary, adding a check to ensure the date string matches the fromFormat would enhance the robustness of your code and prevent potential errors.

  2. 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) {

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.

Comment on lines +28 to +31
if (dateSet.YY < cutoffYear) {
newFormat.push('20' + dateSet.YY);
} else {
newFormat.push('19' + dateSet.YY);

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.

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