88 Text ,
99 Modal ,
1010 Image ,
11+ Alert ,
1112 StyleSheet ,
1213 ScrollView ,
1314 Dimensions ,
@@ -25,6 +26,7 @@ export default class Calendar extends Component {
2526 format : PropTypes . string ,
2627 customI18n : PropTypes . object ,
2728 customStyles : PropTypes . object ,
29+ dateRangeValidator : PropTypes . object ,
2830 color : PropTypes . object ,
2931 minDate : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . instanceOf ( Date ) ] ) ,
3032 maxDate : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . instanceOf ( Date ) ] )
@@ -33,6 +35,7 @@ export default class Calendar extends Component {
3335 format : 'YYYY-MM-DD' ,
3436 customI18n : { } ,
3537 customStyles : { } ,
38+ dateRangeValidator : null ,
3639 color : { }
3740 }
3841 static DEFAULT_I18N_MAP = {
@@ -200,6 +203,16 @@ export default class Calendar extends Component {
200203 } = this . state ;
201204 let startMoment = startDate ? startDate . clone ( ) : null ;
202205 let endMoment = endDate ? endDate . clone ( ) : null ;
206+ if ( startMoment != null && endMoment != null && this . props . dateRangeValidator != null ) {
207+ const daysBetween = endMoment . diff ( startMoment , 'days' ) ;
208+ if ( daysBetween < ( this . props . dateRangeValidator . minDaysBetween || 1 )
209+ || daysBetween > ( this . props . dateRangeValidator . maxDaysBetween || 30 ) ) {
210+ Alert . alert (
211+ this . props . dateRangeValidator . msg || 'Invalid range'
212+ ) ;
213+ return false ;
214+ }
215+ }
203216 this . props . onConfirm && this . props . onConfirm ( {
204217 startDate : startMoment ? startMoment . toDate ( ) : null ,
205218 endDate : endMoment ? endMoment . toDate ( ) : null ,
0 commit comments