henninghall / react-native-date-picker

React Native Date Picker is datetime picker for Android and iOS. It includes date, time and datetime picker modes. The datepicker is customizable and is supporting different languages. It's written with native code to achieve the best possible look, feel and performance.
MIT License
2.21k stars 338 forks source link

Default timeZoneOffsetInMinutes value causing wrong Date in "date" mode #841

Open quememo opened 2 months ago

quememo commented 2 months ago

Describe the bug When using Datepicker in mode="date", the date extracted by onConfirm is not the same as the selected with the UI.

Expected behavior Expected: To get December 2, 1998 as date when using onConfirm: image I get image

To Reproduce Add example code that reproduces the behavior.

  <DatePicker
          modal
          mode="date"
          maximumDate={new Date()}
          minimumDate={new Date(1900, 1, 1)}
          open={open}
          onConfirm={(date) => {
            console.log('🚀 ~ onDate', date)
          }}
        />

Smartphone (please complete the following information):

Proposition I have fixed it with timeZoneOffsetInMinutes={0}. The default behavior of this Timezone offset seems to be problematic. My use case is simply allowing the user to define their birthday. I don't care about the device's timezone for this type of interaction; however, due to the default value, it affects my result. I think it should perhaps be set to 0 for 'date' usage or its use should be reevaluated.