UNPKG

bananas-commerce-admin

Version:

What's this, an admin for apes?

29 lines (26 loc) 648 B
import { Granularity } from "../types"; export const formatDate = ( date: Date, granularity: Granularity, variant: "short" | "long" = "short", locale: string = "sv-SE", ) => { let options: Intl.DateTimeFormatOptions = {}; if (granularity === "day") { options = { day: "numeric", month: "long", ...(variant === "long" && { year: "numeric" }), }; } else if (granularity === "month") { options = { month: "long", year: "numeric", }; } else if (granularity === "year") { options = { year: "numeric", }; } return new Intl.DateTimeFormat(locale, options).format(date); };