-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12209 from ethereum/rm-luxon
refactor: remove luxon package, replace with JS Intl library
- Loading branch information
Showing
10 changed files
with
90 additions
and
111 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
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,20 +1,17 @@ | ||
// TODO: we are using `luxon` package just for this util, should consider rewrite using native JS Date API | ||
import { DateTime } from "luxon" | ||
|
||
import { Lang } from "../types" | ||
|
||
export const INVALID_DATETIME = "Invalid DateTime" | ||
|
||
export const getLocaleTimestamp = (locale: Lang, timestamp: string) => { | ||
let localeTimestamp = DateTime.fromSQL(timestamp) | ||
.setLocale(locale) | ||
.toLocaleString(DateTime.DATE_FULL) | ||
|
||
// Fallback to ISO | ||
if (localeTimestamp === INVALID_DATETIME) { | ||
localeTimestamp = DateTime.fromISO(timestamp) | ||
.setLocale(locale) | ||
.toLocaleString(DateTime.DATE_FULL) | ||
} | ||
return localeTimestamp | ||
export const getLocaleTimestamp = ( | ||
locale: Lang, | ||
timestamp: string, | ||
options?: Intl.DateTimeFormatOptions | ||
) => { | ||
const opts = | ||
options || | ||
({ | ||
year: "numeric", | ||
month: "long", | ||
day: "numeric", | ||
} as Intl.DateTimeFormatOptions) | ||
const date = new Date(timestamp) | ||
return new Intl.DateTimeFormat(locale, opts).format(date) | ||
} |
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