-
Notifications
You must be signed in to change notification settings - Fork 0
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
Update/formattime #101
Update/formattime #101
Conversation
const date = new Date(timeString) | ||
const options = { hour: 'numeric', minute: 'numeric' } | ||
return date.toLocaleTimeString('en-US', options) | ||
if (options && (options.hour || options.minute)) { |
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.
what is the reasoning for wrapping the date's util functions instead of using them on their own? It might be simpler to just call them in the code, but if you had a reason for doing so then this code looks good
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.
it was the same function 3 times that formatted time in 3 different way so now it just takes the 2 values as params: the date string and options (i.e. how we want to format the time)
const date = new Date(timeString) | ||
const options = { hour: 'numeric', minute: 'numeric' } | ||
return date.toLocaleTimeString('en-US', options) | ||
if (options && (options.hour || options.minute)) { |
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.
can you comment this to say why we need this conditional statement, or what the correct format of options
is? might help a future programmer. alternatively, you can expose the specific options keys as function parameters.
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.
yes I can do that!
Updates utils functions
formatDate
,formatTime
, andformatDateMMDDYY
into one:formatDateTime
to further simplify the utility functionality.Updates tests too
VISUALS
Date and time rendering as it should