Skip to content

Commit 91efe0e

Browse files
committed
refactor: remove calendarDate from onDateSelect callback
1 parent 371a08f commit 91efe0e

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

src/hooks/useDatePicker.spec.tsx

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ 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'
6+
import { convertToIso8601, formatDate } from '../utils'
77
import localisationHelpers from '../utils/localisationHelpers'
88
import { useDatePicker, UseDatePickerReturn } from './useDatePicker'
99

@@ -510,34 +510,21 @@ describe('clicking a day', () => {
510510
}
511511
it('should call the callback with correct info for Gregorian calendar', () => {
512512
const date = '2018-01-22'
513-
const { calendarDate, calendarDateString } = renderForClick({
513+
const { calendarDateString } = renderForClick({
514514
calendar: 'gregory',
515515
date,
516516
})
517-
expect(calendarDate.toString()).toEqual(
518-
'2018-01-22T00:00:00+02:00[Africa/Khartoum][u-ca=gregory]'
519-
)
520517
expect(calendarDateString).toEqual('2018-01-22')
521518
})
522519
it('should call the callback with correct info for Ethiopic calendar', () => {
523520
const date = '2015-13-02'
524-
const { calendarDate, calendarDateString } = renderForClick({
521+
const { calendarDateString } = renderForClick({
525522
calendar: 'ethiopic',
526523
date,
527524
})
528525
expect(calendarDateString).toEqual('2015-13-02')
529-
expect(
530-
calendarDate.withCalendar('iso8601').toLocaleString('en-GB')
531-
).toMatch('07/09/2023')
532-
533-
expect(
534-
calendarDate.toLocaleString('en-GB', {
535-
month: 'long',
536-
year: 'numeric',
537-
day: 'numeric',
538-
calendar: 'ethiopic',
539-
})
540-
).toEqual('2 Pagumen 2015 ERA1')
526+
const calendarDate = convertToIso8601(calendarDateString, 'ethiopic')
527+
expect(calendarDate).toEqual({ day: 7, month: 9, year: 2023 })
541528
})
542529
it('should call the callback with correct info for a custom (Nepali) calendar', () => {
543530
const date = '2077-12-30'
@@ -548,7 +535,11 @@ describe('clicking a day', () => {
548535
expect(calendarDateString).toEqual('2077-12-30')
549536
expect(
550537
localisationHelpers.localiseMonth(
551-
calendarDate,
538+
{
539+
year: 20777,
540+
month: 12,
541+
day: 30,
542+
},
552543
{
553544
locale: 'en-NP',
554545
calendar: 'nepali',

src/hooks/useDatePicker.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ type DatePickerOptions = {
2121
date: string
2222
options: PickerOptions
2323
onDateSelect: ({
24-
calendarDate,
2524
calendarDateString,
2625
}: {
27-
calendarDate: Temporal.ZonedDateTime
2826
calendarDateString: string
2927
}) => void
3028
minDate?: string
@@ -150,7 +148,6 @@ export const useDatePicker: UseDatePickerHookType = ({
150148
const selectDate = useCallback(
151149
(zdt: Temporal.ZonedDateTime) => {
152150
onDateSelect({
153-
calendarDate: zdt,
154151
calendarDateString: formatDate(zdt, undefined, date.format),
155152
})
156153
},

src/utils/localisationHelpers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ const localiseWeekLabel = (
113113
}
114114

115115
const localiseMonth = (
116-
zdt: Temporal.ZonedDateTime | Temporal.PlainYearMonth | Temporal.PlainDate,
116+
zdt:
117+
| Temporal.ZonedDateTime
118+
| Temporal.PlainYearMonth
119+
| Temporal.PlainDate
120+
| Temporal.PlainDateLike,
117121
localeOptions: PickerOptions,
118122
format: Intl.DateTimeFormatOptions
119123
) => {

0 commit comments

Comments
 (0)