datetimepicker icon indicating copy to clipboard operation
datetimepicker copied to clipboard

Setting maximumDate skews the day to previous day

Open Pcummings opened this issue 4 years ago • 0 comments

Bug report

Summary

When using maximumDate, the resulting date is the day before the day you actually selected.

Reproducible sample code

const onChange = (event, selectedDate) => {
        const currentDate = selectedDate || date;
        console.log(currentDate);
    };

let minDate = new Date();
minDate.setFullYear(minDate.getFullYear() - 18);

<DateTimePicker
                            value={date}
                            is24Hour={true}
                            mode="date"
                            display="spinner"
                            onChange={onChange}
                            style={{ width: '100%', height: 140 }}
                            maximumDate={minDate}
                        />

Steps to reproduce

  1. Set maximumDate to a date in the past e.g. 18 years from noe
  2. console log selectedDate
  3. The date is a day before what you selected

Describe what you expected to happen:

  1. Set maximumDate to a date in the past e.g. 18 years from noe
  2. console log selectedDate
  3. The date is what you selected

Environment info

Expo SDK 41 "@react-native-community/datetimepicker": "^3.5.2",

... And I'm running in IOS sim on Expo GO

npx react-native info output:

System:
    OS: macOS 11.5.2
    CPU: (4) x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
    Memory: 115.67 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.1 - ~/.nvm/versions/node/v14.17.1/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v14.17.1/bin/yarn
    npm: 7.19.1 - ~/.nvm/versions/node/v14.17.1/bin/npm
    Watchman: 2021.06.07.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.10.1 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
    Android SDK: Not Found
  IDEs:
    Android Studio: 4.2 AI-202.7660.26.42.7351085
    Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild
  Languages:
    Java: 12.0.2 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1 
    react-native: https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz => 0.63.2 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

datetimepicker version: 3.5.2

iOS version: 14.7.1

Pcummings avatar Aug 31 '21 18:08 Pcummings