-
-
Notifications
You must be signed in to change notification settings - Fork 340
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
14 changed files
with
232 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import memoizeOne from "memoize-one"; | ||
import { FrontendLocaleData } from "../../data/translation"; | ||
|
||
// Tuesday, August 10 | ||
export const formatDateWeekday = (dateObj: Date, locale: FrontendLocaleData) => | ||
formatDateWeekdayMem(locale).format(dateObj); | ||
|
||
const formatDateWeekdayMem = memoizeOne( | ||
(locale: FrontendLocaleData) => | ||
new Intl.DateTimeFormat(locale.language, { | ||
weekday: "long", | ||
month: "long", | ||
day: "numeric", | ||
}) | ||
); | ||
|
||
// August 10, 2021 | ||
export const formatDate = (dateObj: Date, locale: FrontendLocaleData) => | ||
formatDateMem(locale).format(dateObj); | ||
|
||
const formatDateMem = memoizeOne( | ||
(locale: FrontendLocaleData) => | ||
new Intl.DateTimeFormat(locale.language, { | ||
year: "numeric", | ||
month: "long", | ||
day: "numeric", | ||
}) | ||
); | ||
|
||
// 10/08/2021 | ||
export const formatDateNumeric = (dateObj: Date, locale: FrontendLocaleData) => | ||
formatDateNumericMem(locale).format(dateObj); | ||
|
||
const formatDateNumericMem = memoizeOne( | ||
(locale: FrontendLocaleData) => | ||
new Intl.DateTimeFormat(locale.language, { | ||
year: "numeric", | ||
month: "numeric", | ||
day: "numeric", | ||
}) | ||
); | ||
|
||
// Aug 10 | ||
export const formatDateShort = (dateObj: Date, locale: FrontendLocaleData) => | ||
formatDateShortMem(locale).format(dateObj); | ||
|
||
const formatDateShortMem = memoizeOne( | ||
(locale: FrontendLocaleData) => | ||
new Intl.DateTimeFormat(locale.language, { | ||
day: "numeric", | ||
month: "short", | ||
}) | ||
); | ||
|
||
// August 2021 | ||
export const formatDateMonthYear = (dateObj: Date, locale: FrontendLocaleData) => | ||
formatDateMonthYearMem(locale).format(dateObj); | ||
|
||
const formatDateMonthYearMem = memoizeOne( | ||
(locale: FrontendLocaleData) => | ||
new Intl.DateTimeFormat(locale.language, { | ||
month: "long", | ||
year: "numeric", | ||
}) | ||
); | ||
|
||
// August | ||
export const formatDateMonth = (dateObj: Date, locale: FrontendLocaleData) => | ||
formatDateMonthMem(locale).format(dateObj); | ||
|
||
const formatDateMonthMem = memoizeOne( | ||
(locale: FrontendLocaleData) => | ||
new Intl.DateTimeFormat(locale.language, { | ||
month: "long", | ||
}) | ||
); | ||
|
||
// 2021 | ||
export const formatDateYear = (dateObj: Date, locale: FrontendLocaleData) => | ||
formatDateYearMem(locale).format(dateObj); | ||
|
||
const formatDateYearMem = memoizeOne( | ||
(locale: FrontendLocaleData) => | ||
new Intl.DateTimeFormat(locale.language, { | ||
year: "numeric", | ||
}) | ||
); |
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,61 @@ | ||
import memoizeOne from "memoize-one"; | ||
import { FrontendLocaleData } from "../../data/translation"; | ||
import { useAmPm } from "./use_am_pm"; | ||
|
||
// August 9, 2021, 8:23 AM | ||
export const formatDateTime = (dateObj: Date, locale: FrontendLocaleData) => | ||
formatDateTimeMem(locale).format(dateObj); | ||
|
||
const formatDateTimeMem = memoizeOne( | ||
(locale: FrontendLocaleData) => | ||
new Intl.DateTimeFormat( | ||
locale.language === "en" && !useAmPm(locale) ? "en-u-hc-h23" : locale.language, | ||
{ | ||
year: "numeric", | ||
month: "long", | ||
day: "numeric", | ||
hour: useAmPm(locale) ? "numeric" : "2-digit", | ||
minute: "2-digit", | ||
hour12: useAmPm(locale), | ||
} | ||
) | ||
); | ||
|
||
// August 9, 2021, 8:23:15 AM | ||
export const formatDateTimeWithSeconds = (dateObj: Date, locale: FrontendLocaleData) => | ||
formatDateTimeWithSecondsMem(locale).format(dateObj); | ||
|
||
const formatDateTimeWithSecondsMem = memoizeOne( | ||
(locale: FrontendLocaleData) => | ||
new Intl.DateTimeFormat( | ||
locale.language === "en" && !useAmPm(locale) ? "en-u-hc-h23" : locale.language, | ||
{ | ||
year: "numeric", | ||
month: "long", | ||
day: "numeric", | ||
hour: useAmPm(locale) ? "numeric" : "2-digit", | ||
minute: "2-digit", | ||
second: "2-digit", | ||
hour12: useAmPm(locale), | ||
} | ||
) | ||
); | ||
|
||
// 9/8/2021, 8:23 AM | ||
export const formatDateTimeNumeric = (dateObj: Date, locale: FrontendLocaleData) => | ||
formatDateTimeNumericMem(locale).format(dateObj); | ||
|
||
const formatDateTimeNumericMem = memoizeOne( | ||
(locale: FrontendLocaleData) => | ||
new Intl.DateTimeFormat( | ||
locale.language === "en" && !useAmPm(locale) ? "en-u-hc-h23" : locale.language, | ||
{ | ||
year: "numeric", | ||
month: "numeric", | ||
day: "numeric", | ||
hour: "numeric", | ||
minute: "2-digit", | ||
hour12: useAmPm(locale), | ||
} | ||
) | ||
); |
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,53 @@ | ||
import memoizeOne from "memoize-one"; | ||
import { FrontendLocaleData } from "../../data/translation"; | ||
import { useAmPm } from "./use_am_pm"; | ||
|
||
// 9:15 PM || 21:15 | ||
export const formatTime = (dateObj: Date, locale: FrontendLocaleData) => | ||
formatTimeMem(locale).format(dateObj); | ||
|
||
const formatTimeMem = memoizeOne( | ||
(locale: FrontendLocaleData) => | ||
new Intl.DateTimeFormat( | ||
locale.language === "en" && !useAmPm(locale) ? "en-u-hc-h23" : locale.language, | ||
{ | ||
hour: "numeric", | ||
minute: "2-digit", | ||
hour12: useAmPm(locale), | ||
} | ||
) | ||
); | ||
|
||
// 9:15:24 PM || 21:15:24 | ||
export const formatTimeWithSeconds = (dateObj: Date, locale: FrontendLocaleData) => | ||
formatTimeWithSecondsMem(locale).format(dateObj); | ||
|
||
const formatTimeWithSecondsMem = memoizeOne( | ||
(locale: FrontendLocaleData) => | ||
new Intl.DateTimeFormat( | ||
locale.language === "en" && !useAmPm(locale) ? "en-u-hc-h23" : locale.language, | ||
{ | ||
hour: useAmPm(locale) ? "numeric" : "2-digit", | ||
minute: "2-digit", | ||
second: "2-digit", | ||
hour12: useAmPm(locale), | ||
} | ||
) | ||
); | ||
|
||
// Tuesday 7:00 PM || Tuesday 19:00 | ||
export const formatTimeWeekday = (dateObj: Date, locale: FrontendLocaleData) => | ||
formatTimeWeekdayMem(locale).format(dateObj); | ||
|
||
const formatTimeWeekdayMem = memoizeOne( | ||
(locale: FrontendLocaleData) => | ||
new Intl.DateTimeFormat( | ||
locale.language === "en" && !useAmPm(locale) ? "en-u-hc-h23" : locale.language, | ||
{ | ||
weekday: "long", | ||
hour: useAmPm(locale) ? "numeric" : "2-digit", | ||
minute: "2-digit", | ||
hour12: useAmPm(locale), | ||
} | ||
) | ||
); |
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,13 @@ | ||
import memoizeOne from "memoize-one"; | ||
import { FrontendLocaleData, TimeFormat } from "../../data/translation"; | ||
|
||
export const useAmPm = memoizeOne((locale: FrontendLocaleData): boolean => { | ||
if (locale.time_format === TimeFormat.language || locale.time_format === TimeFormat.system) { | ||
const testLanguage = | ||
locale.time_format === TimeFormat.language ? locale.language : undefined; | ||
const test = new Date().toLocaleString(testLanguage); | ||
return test.includes("AM") || test.includes("PM"); | ||
} | ||
|
||
return locale.time_format === TimeFormat.am_pm; | ||
}); |
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