diff options
author | João Augusto Costa Branco Marado Torres <torres.dev@disroot.org> | 2025-08-05 18:50:37 +0100 |
---|---|---|
committer | João Augusto Costa Branco Marado Torres <torres.dev@disroot.org> | 2025-08-05 18:50:37 +0100 |
commit | 0af094770c4ebabc56ff761a8bd215bc397c0f7e (patch) | |
tree | a9ad669c8b84b4d13897732ed93ccfcbbeb2cb25 /src/utils/datetime.ts | |
parent | 84eef3f848c4efa18985a776021a58720744523a (diff) |
refactor: reading page review
Signed-off-by: João Augusto Costa Branco Marado Torres <torres.dev@disroot.org>
Diffstat (limited to 'src/utils/datetime.ts')
-rw-r--r-- | src/utils/datetime.ts | 18 |
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)); +} |