Skip to content

Commit

Permalink
fix: minimumDate and maximumDate with (milli)seconds prevents onC…
Browse files Browse the repository at this point in the history
…hange to be called (#760)
  • Loading branch information
yfyau authored Feb 12, 2024
1 parent 58c5634 commit 0151e2c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .maestro/minimum-date.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ tags:
- runFlow: utils/swipe-wheel-3-up.yml
- assertVisible: '2000-01-01 23:59:00'

### test: should ignore seconds and milliseconds
- runFlow:
file: utils/change-minimum-date.yml
env:
VALUE: '2000-01-01 23:59:59.999'
- runFlow: utils/swipe-wheel-2-up.yml
- assertVisible: '2000-01-01 23:59:00'

### test: date mode

- runFlow: utils/change-mode-date.yml
Expand Down
16 changes: 15 additions & 1 deletion src/DatePickerAndroid.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ class DatePickerAndroid extends React.PureComponent {

if (props.modal) return null

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

getId = () => {
Expand Down Expand Up @@ -110,6 +117,13 @@ 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 0151e2c

Please sign in to comment.