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
674 stars 176 forks source link

Error on day selection (-1 day) #428

Open Reggionick opened 1 month ago

Reggionick commented 1 month ago

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

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

I had an issue on some dates (I still don't know why this is not systematic) where the selected date was the day before today (-2 from UTC). In attachment a screenshot with the selected date with the difference from the highlighted one.

Screenshot 2024-10-24 at 22 53 19

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-paper-dates/src/Date/Day.tsx b/node_modules/react-native-paper-dates/src/Date/Day.tsx
index 56bcee6..fcf34ae 100644
--- a/node_modules/react-native-paper-dates/src/Date/Day.tsx
+++ b/node_modules/react-native-paper-dates/src/Date/Day.tsx
@@ -53,7 +53,7 @@ function Day(props: {
   const borderColor = theme.isV3 ? theme.colors.primary : v2BorderColor

   const onPress = useCallback(() => {
-    onPressDate(new Date(year, month, day))
+    onPressDate(new Date(Date.UTC(year, month, day)))
   }, [onPressDate, year, month, day])

   // TODO: check if this can be simplified

This issue body was partially generated by patch-package.

github-actions[bot] commented 1 month ago

Hey! Thanks for opening the issue. Can you provide a minimal repro which demonstrates the issue? Posting a snippet of your code in the issue is useful, but it's not usually straightforward to run. A repro will help us debug the issue faster. Please try to keep the repro as small as possible. The easiest way to provide a repro is on snack.expo.dev. If it's not possible to repro it on snack.expo.dev, then you can also provide the repro in a GitHub repository.

github-actions[bot] commented 1 month ago

Hey! Thanks for opening the issue. Can you provide more information about the issue? Please fill the issue template when opening the issue without deleting any section. We need all the information we can, to be able to help. Make sure to at least provide - Current behaviour, Expected behaviour, A way to reproduce the issue with minimal code (link to snack.expo.dev) or a repo on GitHub, and the information about your environment (such as the platform of the device, versions of all the packages etc.).