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
662 stars 170 forks source link

Select one day, but it shows as +1 day #268

Closed G2454 closed 1 year ago

G2454 commented 1 year ago

Hello, I'm having trouble with the date range picker. Every time I pick an endDate It ends up +1 day. If i choose 2023-03-03, it shows as "2023-03-04T02:59:59.000Z" in the console.log. Since my timezone is GMT-3, I suppose it's converting automaticaly to the timezone this library uses after I pick the date, adding +1 day. Is there a way to solve this ?

Example: (startDate = 2023-03-01, endDate = 2023-03-03 image

After putting this line of code in 40 <Text style={{color:'black'}}>{JSON.stringify(range.endDate)}</Text> It shows the wrong date (chosen date +1) image

This was made on: https://snack.expo.dev/@fitzwabs/react-native-paper-dates-range-picker?platform=web I just added a single line of code to display the endDate Locale is set as 'pt'

RichardLindhout commented 1 year ago

It picks the end day of the timezone of the device are you on a emulator?

G2454 commented 1 year ago

No, I'm using It on my Android device through Expo Go. But this problem happens both with the snack (web) and with my device. This problem doesn't happen in the demo :https://www.reactnativepaperdates.com/ , so I was hoping there is some trick to solve it

G2454 commented 1 year ago

I somehow solved this problem. I installed moment.js to my project, put this line of code let endDate = moment(range.endDate).utcOffset('-03:00').format('DD/MM/YYYY HH:mm:ss'); . It solved the timezone problem