web-ridge / react-native-paper-dates

Smooth and fast cross platform Material Design date and time picker for React Native Paper
https://www.reactnativepaperdates.com
MIT License
654 stars 170 forks source link

Null value as default gets 01/01/1970 on field #175

Closed cywiretech closed 2 years ago

cywiretech commented 2 years ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-paper-dates@0.8.7 for the project I'm working on.

Hi! I found this issue using expo and running expo web on chromium. If i use the null value for the start date value, i see 01/01/1970 instead of the empty field. This patch resolve the issue, i hope it is right

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-paper-dates/lib/module/Date/inputUtils.js b/node_modules/react-native-paper-dates/lib/module/Date/inputUtils.js
index cdf3d0e..af926e0 100644
--- a/node_modules/react-native-paper-dates/lib/module/Date/inputUtils.js
+++ b/node_modules/react-native-paper-dates/lib/module/Date/inputUtils.js
@@ -23,7 +23,7 @@ export default function useDateInput(_ref) {
     formatter,
     locale
   });
-  const formattedValue = formatter.format(value);
+  const formattedValue = value !== null ? formatter.format(value) : '';

   const onChangeText = date => {
     const dayIndex = inputFormat.indexOf('DD');

This issue body was partially generated by patch-package.

RichardLindhout commented 2 years ago

Thank you! Will add this in next release