-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
add solution #2288
base: master
Are you sure you want to change the base?
add solution #2288
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.
Great job on implementing the formatDate
function! 🎉 While there are a few areas for improvement, such as making the year conversion logic more flexible and dynamically determining the separator, your code meets the core requirements and functions as expected. 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! ✨
const oldSeparator = fromFormat[3]; | ||
const oldDate = date.split(oldSeparator); | ||
const newSeparator = toFormat[3]; |
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 assumption that the separator is always at the fourth position in the format arrays (fromFormat[3]
and toFormat[3]
) may not be valid. Consider dynamically determining the separator by checking the format strings.
if (fromFormat[oldYearPosition].length > toFormat[newYearPosition].length) { | ||
oldDate[oldYearPosition] = | ||
oldDate[oldYearPosition][2] + oldDate[oldYearPosition][3]; | ||
} |
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 here assumes that the year is always four characters long in the fromFormat
and two characters long in the toFormat
. This may not always be the case. Consider adding checks to ensure that the indices used are valid and handle cases where the year length differs.
if (fromFormat[oldYearPosition].length < toFormat[newYearPosition].length) { | ||
if (+oldDate[oldYearPosition] < 30) { | ||
oldDate[oldYearPosition] = 20 + oldDate[oldYearPosition]; | ||
} else { | ||
oldDate[oldYearPosition] = 19 + oldDate[oldYearPosition]; | ||
} | ||
} |
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 two-digit years to four-digit years assumes that any year less than 30 should be prefixed with '20' and others with '19'. This may not be a valid assumption for all use cases. Consider making this logic more flexible or configurable.
No description provided.