Skip to content

Commit

Permalink
fix: enforce valid date format
Browse files Browse the repository at this point in the history
  • Loading branch information
gciotola committed Feb 6, 2025
1 parent a7a79e2 commit 09d4822
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/app-elements/src/helpers/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,16 +331,19 @@ export function formatDateRange({
timezone = 'UTC',
locale = 'en-US'
}: {
/** JavaScript ISO date string. Example '2022-10-06T11:59:30.371Z' */
rangeFrom: DateISOString
/** JavaScript ISO date string. Example '2022-11-06T11:59:30.371Z' */
rangeTo: DateISOString
/** JavaScript Date or ISO string. Example '2022-10-06T11:59:30.371Z' */
rangeFrom: DateISOString | Date
/** JavaScript Date or ISO string. Example '2022-11-06T11:59:30.371Z' */
rangeTo: DateISOString | Date
/** Set a specific timezone, when not passed default value is 'UTC' */
timezone?: string
/** Locale to use for formatting the date. */
locale?: I18NLocale
zonedAlready?: boolean
}): string {
rangeFrom = new Date(rangeFrom).toISOString()
rangeTo = new Date(rangeTo).toISOString()

if (isSameYear(rangeFrom, rangeTo) && isSameMonth(rangeFrom, rangeTo)) {
const dayOfMonthFrom = formatInTimeZone(rangeFrom, timezone, 'd', {
locale: getLocaleOption(locale)
Expand Down

0 comments on commit 09d4822

Please sign in to comment.