Skip to content

Commit 149e12e

Browse files
committed
feat: remove calendar date from use date picker
1 parent 2996cc5 commit 149e12e

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/hooks/useDatePicker.spec.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Intl } from '@js-temporal/polyfill'
1+
import { Intl, Temporal } from '@js-temporal/polyfill'
22
import { render } from '@testing-library/react'
33
import { renderHook } from '@testing-library/react-hooks'
44
import React from 'react'
55
import { SupportedCalendar } from '../types'
6+
import { formatDate } from '../utils'
67
import localisationHelpers from '../utils/localisationHelpers'
78
import { useDatePicker, UseDatePickerReturn } from './useDatePicker'
89

@@ -271,13 +272,21 @@ describe('useDatePicker hook', () => {
271272
})
272273
describe('highlighting today', () => {
273274
const getDayByDate: (
274-
calendarWeekDays: { calendarDate: string; isToday: boolean }[][],
275+
calendarWeekDays: {
276+
isToday: boolean
277+
zdt: Temporal.ZonedDateTime
278+
}[][],
275279
dayToFind: string
276280
) => { calendarDate: string; isToday: boolean }[] = (
277281
calendarWeekDays,
278282
dayToFind
279283
) => {
280-
const days = calendarWeekDays.flatMap((week) => week)
284+
const days = calendarWeekDays
285+
.flatMap((week) => week)
286+
.map((day) => ({
287+
...day,
288+
calendarDate: formatDate(day.zdt, undefined, 'YYYY-MM-DD'),
289+
}))
281290

282291
return days.filter((day) => day.calendarDate === dayToFind)
283292
}
@@ -485,7 +494,12 @@ describe('clicking a day', () => {
485494

486495
// find and click the day passed to the calendar
487496
for (let i = 0; i < days.length; i++) {
488-
if (days[i].calendarDate === date) {
497+
const formattedDate = formatDate(
498+
days[i].zdt,
499+
undefined,
500+
'YYYY-MM-DD'
501+
)
502+
if (formattedDate === date) {
489503
days[i].onClick()
490504
break
491505
}

src/hooks/useDatePicker.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,12 @@ export type UseDatePickerReturn = UseNavigationReturnType & {
3838
calendarWeekDays: {
3939
zdt: Temporal.ZonedDateTime
4040
label: string | number
41-
calendarDate: string
4241
onClick: () => void
4342
isSelected: boolean | undefined
4443
isToday: boolean
4544
isInCurrentMonth: boolean
4645
}[][]
4746
}
48-
4947
type UseDatePickerHookType = (options: DatePickerOptions) => UseDatePickerReturn
5048
type ValidatedDate = Temporal.YearOrEraAndEraYear &
5149
Temporal.MonthOrMonthCode & {
@@ -194,7 +192,6 @@ export const useDatePicker: UseDatePickerHookType = ({
194192
calendarWeekDays: calendarWeekDaysZdts.map((week) =>
195193
week.map((weekDayZdt) => ({
196194
zdt: weekDayZdt,
197-
calendarDate: formatDate(weekDayZdt, undefined, date.format),
198195
label: localisationHelpers.localiseWeekLabel(
199196
weekDayZdt.withCalendar(localeOptions.calendar),
200197
localeOptions

0 commit comments

Comments
 (0)