datetimepicker
datetimepicker copied to clipboard
Unable to select a date earlier than Unix epoch when only a maximum date is provided on Android
Bug report
Summary
If a maximumDate is provided, but a minimumDate is not, the Android date picker does not allow the user to go earlier than the Unix epoch (1970-01-01 00:00).
The workaround I found was to manually set an unrealistic minimumDate. You can also remove the maximum date, but in our case that is not an option.
Reproducible sample code
import { useState } from "react";
import { SafeAreaProvider, SafeAreaView } from "react-native-safe-area-context";
import DateTimePicker from "@react-native-community/datetimepicker";
import { View, Button, Text } from "react-native";
export default function BugReport() {
const [show, setShow] = useState(false);
const [withMaxDate, setWithMaxDate] = useState(true);
const [withMinDate, setWithMinDate] = useState(false);
return (
<SafeAreaProvider>
<SafeAreaView>
<View style={{ gap: 5 }}>
<View>
<Text>
Max date: {withMaxDate ? "on" : "off"}; Min date:{" "}
{withMinDate ? "on" : "off"}
</Text>
</View>
<Button onPress={() => setShow(true)} title="Select a date" />
<Button
onPress={() => setWithMaxDate((c) => !c)}
title="Toggle max date"
/>
<Button
onPress={() => setWithMinDate((c) => !c)}
title="Toggle min date"
/>
{show && (
<DateTimePicker
maximumDate={withMaxDate ? new Date(2006, 0, 1) : undefined}
minimumDate={withMinDate ? new Date(1900, 0, 1) : undefined}
value={new Date(1970, 0, 2)}
mode={"date"}
onChange={() => setShow(false)}
/>
)}
</View>
</SafeAreaView>
</SafeAreaProvider>
);
}
https://github.com/czycha/rn-datepicker-min-date-bug has this code here
Steps to reproduce
- Start an app on an Android device with the above code.
- Click the "Select a date" button.
- Try to select a date older than 1970-1-1 UTC (depending on timezone, this could mean older than Dec 31 1969).
Describe what you expected to happen:
- Given that there's no minimum date selected, you should be able to select a date older than the Unix epoch (but you cannot).
Environment info
npx react-native info output:
System:
OS: macOS 14.6.1
CPU: (12) arm64 Apple M2 Pro
Memory: 279.92 MB / 32.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 22.6.0
path: ~/.nvm/versions/node/v22.6.0/bin/node
Yarn:
version: 1.22.22
path: /opt/homebrew/bin/yarn
npm:
version: 10.8.2
path: ~/.nvm/versions/node/v22.6.0/bin/npm
Watchman:
version: 2024.08.12.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.15.2
path: /Users/bruno/.rbenv/shims/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 24.0
- iOS 18.0
- macOS 15.0
- tvOS 18.0
- visionOS 2.0
- watchOS 11.0
Android SDK:
API Levels:
- "31"
- "33"
- "34"
Build Tools:
- 30.0.3
- 31.0.0
- 34.0.0
System Images:
- android-34 | Google APIs ARM 64 v8a
- android-35 | Google Play ARM 64 v8a
Android NDK: Not Found
IDEs:
Android Studio: 2023.2 AI-232.10300.40.2321.11668458
Xcode:
version: 16.0/16A242d
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.12
path: /usr/bin/javac
Ruby:
version: 3.0.0
path: /Users/bruno/.rbenv/shims/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.74.5
wanted: 0.74.5
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: Not found
newArchEnabled: Not found
iOS:
hermesEnabled: Not found
newArchEnabled: Not found
datetimepicker version: 8.2.1
Android version: 15
Expo: 51.0.36
Facing the same issue. We have our maximum date set to three years from the current date and no minimum date. However what @czycha suggested does work and is a temporary workaround for thus
Got the same issue