-
-
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 2 commits
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
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. In a util functions file, we should be documenting each function as much as possible so other people know how to use it. Add some comments here to describe the function. Make sure to mention what arguments it takes and what it returns. |
||
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 }; | ||
} 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 |
||
} | ||
} | ||
|
||
// format must be 'long' or 'short' | ||
function getTimeZoneWithFormat(date, format) { | ||
try { | ||
const formatter = new Intl.DateTimeFormat('en-US', { timeZoneName: format }); | ||
return formatter.formatToParts(date).find(part => { | ||
return part.type === 'timeZoneName'; | ||
}).value || ''; | ||
} catch { | ||
return ''; | ||
} | ||
} | ||
|
||
export { getDateTime, getTimeZoneWithFormat }; | ||
|
This file was deleted.
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.
Move this logic into datetime_utils by creating a function called "getDayOfWeek"