summaryrefslogtreecommitdiff
path: root/src/utils/datetime.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/datetime.ts')
-rw-r--r--src/utils/datetime.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/utils/datetime.ts b/src/utils/datetime.ts
index c32fde0..be2ce08 100644
--- a/src/utils/datetime.ts
+++ b/src/utils/datetime.ts
@@ -1,3 +1,5 @@
+import { createRanges } from "./iterator.ts";
+
export function toIso8601Full(date: Date): string {
const yearN = date.getFullYear();
const isNegativeYear = yearN <= 0;
@@ -66,3 +68,19 @@ export function getRelativeTimeUnit(
if (Math.abs(minutes) >= 1) return [Math.round(minutes), "minute"];
return [Math.round(seconds), "second"];
}
+
+export function listDates(dates: Date[], { date, locale, list }: {
+ date: Intl.DateTimeFormatOptions;
+ locale: Intl.LocalesArgument;
+ list: Intl.ListFormatOptions;
+}): string {
+ const formatter = new Intl.DateTimeFormat(locale, date);
+ return new Intl.ListFormat(locale, list).format(dates.map(formatter.format));
+}
+
+export function listYearsWithRanges(years: number[], { locale, list }: {
+ locale: Intl.LocalesArgument;
+ list: Intl.ListFormatOptions;
+}): string {
+ return new Intl.ListFormat(locale, list).format(createRanges(years));
+}