Skip to content

Commit f5775a6

Browse files
authored
fix: occasional setSeconds errors on min/maxDate (#766)
* fix: occasional setSeconds error on min/maxDate * null check
1 parent 37ceab4 commit f5775a6

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

android/src/main/java/com/henninghall/date_picker/State.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.henninghall.date_picker;
22

3-
import android.util.Log;
4-
53
import com.facebook.react.bridge.Dynamic;
64
import com.henninghall.date_picker.models.Is24HourSource;
75
import com.henninghall.date_picker.models.Mode;
@@ -97,11 +95,23 @@ public Locale getLocale() {
9795
}
9896

9997
public Calendar getMinimumDate() {
100-
return Utils.isoToCalendar(minimumDateProp.getValue(), getTimeZone());
98+
return boundaryPropToCal(minimumDateProp);
10199
}
102100

103101
public Calendar getMaximumDate() {
104-
return Utils.isoToCalendar(maximumDateProp.getValue(), getTimeZone());
102+
return boundaryPropToCal(maximumDateProp);
103+
}
104+
105+
private Calendar boundaryPropToCal(Prop<String> prop){
106+
Calendar cal = Utils.isoToCalendar(prop.getValue(), getTimeZone());
107+
clearSecondsAndMilliseconds(cal);
108+
return cal;
109+
}
110+
111+
private void clearSecondsAndMilliseconds(Calendar cal) {
112+
if (cal == null) return;
113+
cal.set(Calendar.SECOND, 0);
114+
cal.set(Calendar.MILLISECOND, 0);
105115
}
106116

107117
public TimeZone getTimeZone() {

src/DatePickerAndroid.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,7 @@ class DatePickerAndroid extends React.PureComponent {
2727

2828
if (props.modal) return null
2929

30-
return (
31-
<NativeComponent
32-
{...props}
33-
maximumDate={this._withoutSecond(props.maximumDate)}
34-
minimumDate={this._withoutSecond(props.minimumDate)}
35-
onChange={this._onChange}
36-
/>
37-
)
30+
return <NativeComponent {...props} onChange={this._onChange} />
3831
}
3932

4033
getId = () => {
@@ -117,13 +110,6 @@ class DatePickerAndroid extends React.PureComponent {
117110
this.isClosing = true
118111
this.props.onCancel()
119112
}
120-
121-
_withoutSecond = (date) => {
122-
if (!date) return date
123-
date.setSeconds(0)
124-
date.setMilliseconds(0)
125-
return date
126-
}
127113
}
128114

129115
export default DatePickerAndroid

0 commit comments

Comments
 (0)