omnivore/packages/web/lib/dateFormatting.ts

27 lines
769 B
TypeScript
Raw Normal View History

2022-02-11 17:24:33 +00:00
//https://github.com/you-dont-need/You-Dont-Need-Momentjs
export const locale = Intl.DateTimeFormat().resolvedOptions().locale || 'en-US'
// get the user's time zone
export const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
2022-02-11 17:24:33 +00:00
export function formattedLongDate(rawDate: string): string {
return new Intl.DateTimeFormat(locale, {
dateStyle: 'long',
timeZone,
2022-02-11 17:24:33 +00:00
}).format(new Date(rawDate))
}
export function formattedShortDate(rawDate: string): string {
return new Intl.DateTimeFormat(locale, {
dateStyle: 'short',
timeZone,
}).format(new Date(rawDate))
}
export function formattedShortTime(rawDate: string): string {
return new Intl.DateTimeFormat(locale, {
timeStyle: 'short',
timeZone,
}).format(new Date(rawDate))
}