Skip to content

Commit

Permalink
Merge pull request #30845 from allroundexperts/fix-30792
Browse files Browse the repository at this point in the history
[CP Staging] fix: use parseISO instead od Date
  • Loading branch information
mountiny authored Nov 3, 2023
2 parents 55d31b7 + 1680a11 commit 7a70056
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/components/DatePicker/index.android.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import RNDatePicker from '@react-native-community/datetimepicker';
import {format} from 'date-fns';
import {format, parseISO} from 'date-fns';
import React, {forwardRef, useCallback, useImperativeHandle, useRef, useState} from 'react';
import {Keyboard} from 'react-native';
import TextInput from '@components/TextInput';
Expand Down Expand Up @@ -39,7 +39,7 @@ function DatePicker({value, defaultValue, label, placeholder, errorText, contain
);

const date = value || defaultValue;
const dateAsText = date ? format(new Date(date), CONST.DATE.FNS_FORMAT_STRING) : '';
const dateAsText = date ? format(parseISO(date), CONST.DATE.FNS_FORMAT_STRING) : '';

return (
<>
Expand Down
4 changes: 2 additions & 2 deletions src/components/DatePicker/index.ios.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import RNDatePicker from '@react-native-community/datetimepicker';
import {format} from 'date-fns';
import {format, parseISO} from 'date-fns';
import isFunction from 'lodash/isFunction';
import React, {useCallback, useEffect, useRef, useState} from 'react';
import {Button, Keyboard, View} from 'react-native';
Expand Down Expand Up @@ -77,7 +77,7 @@ function DatePicker({value, defaultValue, innerRef, onInputChange, preferredLoca
setSelectedDate(date);
};

const dateAsText = dateValue ? format(new Date(dateValue), CONST.DATE.FNS_FORMAT_STRING) : '';
const dateAsText = dateValue ? format(parseISO(dateValue), CONST.DATE.FNS_FORMAT_STRING) : '';

return (
<>
Expand Down
4 changes: 2 additions & 2 deletions src/components/DatePicker/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {format, isValid} from 'date-fns';
import {format, isValid, parseISO} from 'date-fns';
import React, {useEffect, useRef} from 'react';
import _ from 'underscore';
import TextInput from '@components/TextInput';
Expand Down Expand Up @@ -29,7 +29,7 @@ function DatePicker({maxDate, minDate, onInputChange, innerRef, label, value, pl
return;
}

const date = new Date(text);
const date = parseISO(text);
if (isValid(date)) {
onInputChange(format(date, CONST.DATE.FNS_FORMAT_STRING));
}
Expand Down

0 comments on commit 7a70056

Please sign in to comment.