Skip to content

Instantly share code, notes, and snippets.

@cherscarlett
Last active March 27, 2021 13:52
Show Gist options
  • Save cherscarlett/9876e219c71190338dfc58eebd5ce12a to your computer and use it in GitHub Desktop.
Save cherscarlett/9876e219c71190338dfc58eebd5ce12a to your computer and use it in GitHub Desktop.
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