Skip to content

Commit 05859e5

Browse files
committed
fix: update input label for pt locale
1 parent abe5863 commit 05859e5

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/Date/dateUtils.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,19 @@ export function getEndOfDay(d: Date): Date {
218218
}
219219
export function useInputFormat({
220220
formatter,
221+
locale,
221222
}: {
222223
formatter: Intl.DateTimeFormat
224+
locale?: string
223225
}) {
224226
return React.useMemo(() => {
225227
// TODO: something cleaner and more universal?
226228
const inputDate = formatter.format(new Date(2020, 10 - 1, 1))
227229
return inputDate
228-
.replace('2020', 'YYYY')
230+
.replace('2020', locale === 'pt' ? 'AAAA' : 'YYYY')
229231
.replace('10', 'MM')
230232
.replace('01', 'DD')
231-
}, [formatter])
233+
}, [formatter, locale])
232234
}
233235

234236
export function differenceInMonths(firstDate: Date, secondDate: Date) {

src/Date/inputUtils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ export default function useDateInput({
2020
useRangeChecker(validRange)
2121
const [error, setError] = React.useState<null | string>(null)
2222
const formatter = useInputFormatter({ locale })
23-
const inputFormat = useInputFormat({ formatter })
23+
const inputFormat = useInputFormat({ formatter, locale })
2424
const formattedValue = formatter.format(value)
2525
const onChangeText = (date: string) => {
2626
const dayIndex = inputFormat.indexOf('DD')
2727
const monthIndex = inputFormat.indexOf('MM')
28-
const yearIndex = inputFormat.indexOf('YYYY')
28+
const yearIndex =
29+
locale === 'pt'
30+
? inputFormat.indexOf('AAAA')
31+
: inputFormat.indexOf('YYYY')
2932

3033
const day = Number(date.slice(dayIndex, dayIndex + 2))
3134
const year = Number(date.slice(yearIndex, yearIndex + 4))

0 commit comments

Comments
 (0)