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 #2163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Solution #2163

wants to merge 1 commit into from

Conversation

maxsabo
Copy link

@maxsabo maxsabo commented Nov 12, 2024

No description provided.

Copy link

@ab3MN ab3MN left a comment

Choose a reason for hiding this comment

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

Good job👍

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.

Great job on implementing the formatDate function! 🎉 Your solution meets the task requirements and constraints effectively. While there are a few areas for improvement, such as handling unexpected year values and making the separator identification more robust, these do not critically impact the functionality of your code. Keep up the good work, and consider these suggestions for future enhancements! 😊

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

@@ -8,7 +8,30 @@
* @returns {string}
*/
function formatDate(date, fromFormat, toFormat) {
// write code here
const separator = fromFormat[3];

Choose a reason for hiding this comment

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

The code assumes that the separator is always at the fourth position in the fromFormat array. This assumption might not hold true for all date formats. Consider a more flexible approach to determine the separator.

dateObj['YYYY'] = year < 30 ? `20${dateObj['YY']}` : `19${dateObj['YY']}`;
}

const newSeparator = toFormat[3];

Choose a reason for hiding this comment

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

Similar to the issue with fromFormat, the code assumes the separator is at the fourth position in the toFormat array. This might not be accurate for all formats. Consider a more robust method to identify the separator.

Comment on lines +20 to +26
if (fromFormat.includes('YYYY') && toFormat.includes('YY')) {
dateObj['YY'] = dateObj['YYYY'].slice(-2);
} else if (fromFormat.includes('YY') && toFormat.includes('YYYY')) {
const year = parseInt(dateObj['YY'], 10);

dateObj['YYYY'] = year < 30 ? `20${dateObj['YY']}` : `19${dateObj['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 between 'YYYY' and 'YY' formats is correct, but it doesn't account for invalid or unexpected year values. Consider adding validation to ensure the year values are within a reasonable range.

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.

3 participants