-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48cb2e2
commit b613cef
Showing
2 changed files
with
8 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,11 @@ | ||
export function dateTimeFormat(timestamp, options) { | ||
const dateTime = new Date(timestamp); | ||
const timeFormatOptions = { | ||
hour: 'numeric', | ||
minute: 'numeric', | ||
second: 'numeric', | ||
}; | ||
const time = new Intl.DateTimeFormat(undefined, timeFormatOptions).format( | ||
dateTime | ||
); | ||
const timeFormatOptions = { timeStyle: 'medium' }; | ||
const dateFormatOptions = { dateStyle: 'medium' }; | ||
|
||
if (options?.timeOnly) { | ||
return time; | ||
} | ||
const chosenOption = options?.timeOnly | ||
? timeFormatOptions | ||
: { ...timeFormatOptions, ...dateFormatOptions }; | ||
|
||
const dateFormatOptions = { month: 'short', day: 'numeric', year: 'numeric' }; | ||
const date = new Intl.DateTimeFormat(undefined, dateFormatOptions).format( | ||
dateTime | ||
); | ||
|
||
return `${date} ${time}`; | ||
return new Intl.DateTimeFormat(undefined, chosenOption).format(dateTime); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters