-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Showing
3 changed files
with
46 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import memoizeOne from "memoize-one"; | ||
|
||
export const localizeWeekdays = memoizeOne( | ||
(language: string, short: boolean): string[] => { | ||
const days: string[] = []; | ||
const format = new Intl.DateTimeFormat(language, { | ||
weekday: short ? "short" : "long", | ||
timeZone: "UTC", | ||
}); | ||
for (let i = 0; i < 7; i++) { | ||
const date = new Date(Date.UTC(1970, 0, 1 + 3 + i)); | ||
days.push(format.format(date)); | ||
} | ||
return days; | ||
} | ||
); | ||
|
||
export const localizeMonths = memoizeOne( | ||
(language: string, short: boolean): string[] => { | ||
const months: string[] = []; | ||
const format = new Intl.DateTimeFormat(language, { | ||
month: short ? "short" : "long", | ||
timeZone: "UTC", | ||
}); | ||
for (let i = 0; i < 12; i++) { | ||
const date = new Date(Date.UTC(1970, 0 + i, 1)); | ||
months.push(format.format(date)); | ||
} | ||
return months; | ||
} | ||
); |
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