From 33f17927c12d1b1de2e8fac29beea502b1c6c201 Mon Sep 17 00:00:00 2001 From: Dlurak <84224239+Dlurak@users.noreply.github.com> Date: Wed, 28 Aug 2024 01:15:12 +0200 Subject: [PATCH] Add a weekday to the date selector --- src/lib/components/input/date/DateSelector.svelte | 2 +- src/lib/utils/dates/custom.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/components/input/date/DateSelector.svelte b/src/lib/components/input/date/DateSelector.svelte index 6009130..fc697bb 100644 --- a/src/lib/components/input/date/DateSelector.svelte +++ b/src/lib/components/input/date/DateSelector.svelte @@ -60,7 +60,7 @@ {#if date} - {stringify(date)} + {stringify(date, { weekday: 'short' })} {:else} {/if} diff --git a/src/lib/utils/dates/custom.ts b/src/lib/utils/dates/custom.ts index c5b1115..d15cfd7 100644 --- a/src/lib/utils/dates/custom.ts +++ b/src/lib/utils/dates/custom.ts @@ -49,11 +49,13 @@ export const currentCustomDate = () => normalToCustomDate(new Date()); interface StringifyProps { includeTime?: boolean; includeDate?: boolean; + weekday?: 'short' | 'long' | 'narrow'; } export const stringify = (d: CustomDate, props: StringifyProps = {}) => { const includeTime = props.includeTime ?? false; const includeDate = props.includeDate ?? true; + const weekday = props.weekday ?? null; const timeOptions: Intl.DateTimeFormatOptions = includeTime ? { @@ -66,7 +68,8 @@ export const stringify = (d: CustomDate, props: StringifyProps = {}) => { ? { day: '2-digit', month: '2-digit', - year: '2-digit' + year: '2-digit', + ...(weekday ? { weekday } : null) } : {};