Skip to content

Commit

Permalink
fix: occasional setSeconds errors on min/maxDate (#766)
Browse files Browse the repository at this point in the history
* fix: occasional setSeconds error on min/maxDate

* null check
  • Loading branch information
henninghall authored Feb 26, 2024
1 parent 37ceab4 commit f5775a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
18 changes: 14 additions & 4 deletions android/src/main/java/com/henninghall/date_picker/State.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.henninghall.date_picker;

import android.util.Log;

import com.facebook.react.bridge.Dynamic;
import com.henninghall.date_picker.models.Is24HourSource;
import com.henninghall.date_picker.models.Mode;
Expand Down Expand Up @@ -97,11 +95,23 @@ public Locale getLocale() {
}

public Calendar getMinimumDate() {
return Utils.isoToCalendar(minimumDateProp.getValue(), getTimeZone());
return boundaryPropToCal(minimumDateProp);
}

public Calendar getMaximumDate() {
return Utils.isoToCalendar(maximumDateProp.getValue(), getTimeZone());
return boundaryPropToCal(maximumDateProp);
}

private Calendar boundaryPropToCal(Prop<String> prop){
Calendar cal = Utils.isoToCalendar(prop.getValue(), getTimeZone());
clearSecondsAndMilliseconds(cal);
return cal;
}

private void clearSecondsAndMilliseconds(Calendar cal) {
if (cal == null) return;
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
}

public TimeZone getTimeZone() {
Expand Down
16 changes: 1 addition & 15 deletions src/DatePickerAndroid.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@ class DatePickerAndroid extends React.PureComponent {

if (props.modal) return null

return (
<NativeComponent
{...props}
maximumDate={this._withoutSecond(props.maximumDate)}
minimumDate={this._withoutSecond(props.minimumDate)}
onChange={this._onChange}
/>
)
return <NativeComponent {...props} onChange={this._onChange} />
}

getId = () => {
Expand Down Expand Up @@ -117,13 +110,6 @@ class DatePickerAndroid extends React.PureComponent {
this.isClosing = true
this.props.onCancel()
}

_withoutSecond = (date) => {
if (!date) return date
date.setSeconds(0)
date.setMilliseconds(0)
return date
}
}

export default DatePickerAndroid

0 comments on commit f5775a6

Please sign in to comment.