-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Added datetime helper function #337
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,10 +224,10 @@ function Banner() { | |
style={{ marginBottom: 10, fontWeight: 500 }} | ||
component='h3' | ||
> | ||
<time dateTime={hothStart.toISOString()} hidden> | ||
{month} {startDay}{endDayString}, 2022 | ||
<b>Date: </b><time dateTime={hothStart.toISOString()} > | ||
{month} {startDay}{endDayString}, 2023 | ||
</time> | ||
<b>Date:</b> Sunday, March 5, 2023 | ||
{/* <b>Date:</b> Sunday, March 5, 2023 */} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are not using this code anymore, then you should delete it to keep our code clean. |
||
</Typography> | ||
</Tooltip> | ||
</Box> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export function getDateTime(timestamp) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, there seems to be a |
||
try { | ||
const d = new Date(timestamp); | ||
const date = d.toLocaleDateString('en-US'); | ||
const time = d.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' }); | ||
return `${date}, ${time}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't be returning a string with a specific format like
This function should be able to handle either regardless. To fix this, we should instead return an object that maps keys to values so that each component can use the data however it wants. Like so: return {
date: date,
time: time
} And conveniently, javascript lets a simplify this code into the following that does the exact same thing: return { date, time } Then, in your components, you can use it like so:
|
||
} catch { | ||
return ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return null instead, the default of an empty object |
||
} | ||
} |
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.
We should not be hardcoding the year, but also getting the year from the hothStart date.