Skip to content

Commit

Permalink
Fixed Issue react-native-datetimepicker#935: Unable to select a date …
Browse files Browse the repository at this point in the history
…earlier than Unix epoch when only a maximum date is provided on Android
  • Loading branch information
FiratDede committed Nov 5, 2024
1 parent 80446e4 commit fc25826
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,10 @@ public static long maxDateWithTimeZone(Bundle args) {
}

public static long minDateWithTimeZone(Bundle args) {
if (!args.containsKey(RNConstants.ARG_MINDATE)) {
return 0;
}

Calendar minDate = Calendar.getInstance(getTimeZone(args));
minDate.setTimeInMillis(args.getLong(RNConstants.ARG_MINDATE));
long minDateTimeInMillis = args.containsKey(RNConstants.ARG_MINDATE) ? args.getLong(RNConstants.ARG_MINDATE) : RNConstants.DEFAULT_MIN_DATE;

minDate.setTimeInMillis(minDateTimeInMillis);
minDate.set(Calendar.HOUR_OF_DAY, 0);
minDate.set(Calendar.MINUTE, 0);
minDate.set(Calendar.SECOND, 0);
Expand Down

3 comments on commit fc25826

@Orest1996
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fix doesnt work properly also, minimumDate property is ignored, but minimumDate is now not blocked to 1970, the current minimum date is 1900 yearImage

@Orest1996
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so basically problem with this issue that in the Common.java variable "RNConstants.ARG_MINDATE" doesn't receive value provided by user in "minimumDate".

@FiratDede
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, problem is that when you only provide maximum date, and you don't provide min date in react-native side, your min date set as 1970 year. I don't whether this is a bug or not, because you set a maximum date in this case. I can change this behavior but I think this is not a big problem. And my PR only changes minDate default as 01 Jan 1900. So Actually I will close my PR and I might change the code to give a good result in some situations such as maxDate provided but minDate is not provided.

Please sign in to comment.