From 0af094770c4ebabc56ff761a8bd215bc397c0f7e Mon Sep 17 00:00:00 2001 From: João Augusto Costa Branco Marado Torres Date: Tue, 5 Aug 2025 18:50:37 +0100 Subject: refactor: reading page review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Augusto Costa Branco Marado Torres --- src/utils/datetime.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/utils/datetime.ts') 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)); +} -- cgit v1.2.3