-
Notifications
You must be signed in to change notification settings - Fork 3
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
d199a36
commit 8f84cae
Showing
4 changed files
with
30 additions
and
12 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
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
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
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,13 +1,23 @@ | ||
const prettifyDate = (dateString: string | undefined) => { | ||
if(!dateString) return "" | ||
type OptionsType = { | ||
weekday?: "narrow" | "short" | "long"; | ||
year?: "numeric" | "2-digit"; | ||
month?: "numeric" | "2-digit" | "narrow" | "short" | "long"; | ||
day?: "numeric" | "2-digit"; | ||
hour?: "numeric" | "2-digit"; | ||
minute?: "numeric" | "2-digit"; | ||
second?: "numeric" | "2-digit"; | ||
timeZoneName?: "short" | "long"; | ||
hour12?: boolean; | ||
era?: "narrow" | "short" | "long"; | ||
timeZone?: string; | ||
fractionalSecondDigits?: 1 | 2 | 3; | ||
}; | ||
|
||
const prettifyDate = (dateString: string | undefined, options: OptionsType) => { | ||
if (!dateString) return "" | ||
const date = new Date(dateString); | ||
|
||
return new Intl.DateTimeFormat("en-US", { | ||
// weekday: "short", | ||
year: "numeric", | ||
month: "short", | ||
day: "numeric", | ||
}).format(date); | ||
return new Intl.DateTimeFormat("en-US", options).format(date); | ||
}; | ||
|
||
export default prettifyDate; |