Last active
March 27, 2021 13:52
-
-
Save cherscarlett/9876e219c71190338dfc58eebd5ce12a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
interface Time { | |
hour: string, | |
minute: string, | |
dayPeriod: string | |
} | |
someFunction(dateParts: Intl.DateTimeFormatPart[]): Time { | |
const {hour, minute, dayPeriod} = | |
dateParts.reduce( | |
(time, part) => (time[part.type] = part.value, time), | |
{} as Record<Intl.DateTimeFormatPartTypes, string> | |
); | |
return { hour, minute, dayPeriod }; | |
} | |
// This deconstructs the time from Intl formatted date parts in typescript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment