Created
July 27, 2016 21:00
-
-
Save abiodun0/883df106eb68ec0d78b5c80cbde16747 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getDate: function(driverDobParam) { | |
const givenDate = driverDobParam || this.state.formDob || this.props.dob; | |
const timestamp = Date.parse(givenDate); | |
let dateGiven; | |
if (!isNaN(timestamp)) { | |
dateGiven = new Date(timestamp); | |
} | |
return dateGiven; | |
}, | |
validatedDate: function(givenDate) { | |
const thisYear = (new Date()).getFullYear(); | |
const oldestYear = thisYear - 116; | |
return givenDate >= oldestYear && givenDate <= this.minDriverDob; | |
}, | |
isValid: function(driverDobParam) { | |
const finalDate = this.getDate(driverDobParam); | |
let isValid; | |
if (!finalDate) { | |
isValid = false; | |
} | |
else { | |
isValid = this.validatedDate(finalDate); | |
} | |
return isValid; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment