File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -218,17 +218,19 @@ export function getEndOfDay(d: Date): Date {
218218}
219219export 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
234236export function differenceInMonths ( firstDate : Date , secondDate : Date ) {
Original file line number Diff line number Diff 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 ) )
You can’t perform that action at this time.
0 commit comments