From 05859e5ff886797dc5da8afdd73ec61724fa434b Mon Sep 17 00:00:00 2001 From: Brandon Ebersohl Date: Thu, 6 Jan 2022 08:22:07 -0900 Subject: [PATCH] fix: update input label for pt locale --- src/Date/dateUtils.tsx | 6 ++++-- src/Date/inputUtils.ts | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Date/dateUtils.tsx b/src/Date/dateUtils.tsx index 3f2753e1..aec4ee02 100644 --- a/src/Date/dateUtils.tsx +++ b/src/Date/dateUtils.tsx @@ -218,17 +218,19 @@ export function getEndOfDay(d: Date): Date { } export function useInputFormat({ formatter, + locale, }: { formatter: Intl.DateTimeFormat + locale?: string }) { return React.useMemo(() => { // TODO: something cleaner and more universal? const inputDate = formatter.format(new Date(2020, 10 - 1, 1)) return inputDate - .replace('2020', 'YYYY') + .replace('2020', locale === 'pt' ? 'AAAA' : 'YYYY') .replace('10', 'MM') .replace('01', 'DD') - }, [formatter]) + }, [formatter, locale]) } export function differenceInMonths(firstDate: Date, secondDate: Date) { diff --git a/src/Date/inputUtils.ts b/src/Date/inputUtils.ts index 1f913470..99591c59 100644 --- a/src/Date/inputUtils.ts +++ b/src/Date/inputUtils.ts @@ -20,12 +20,15 @@ export default function useDateInput({ useRangeChecker(validRange) const [error, setError] = React.useState(null) const formatter = useInputFormatter({ locale }) - const inputFormat = useInputFormat({ formatter }) + const inputFormat = useInputFormat({ formatter, locale }) const formattedValue = formatter.format(value) const onChangeText = (date: string) => { const dayIndex = inputFormat.indexOf('DD') const monthIndex = inputFormat.indexOf('MM') - const yearIndex = inputFormat.indexOf('YYYY') + const yearIndex = + locale === 'pt' + ? inputFormat.indexOf('AAAA') + : inputFormat.indexOf('YYYY') const day = Number(date.slice(dayIndex, dayIndex + 2)) const year = Number(date.slice(yearIndex, yearIndex + 4))