Skip to content

Instantly share code, notes, and snippets.

@abiodun0
Created July 27, 2016 21:00
Show Gist options
  • Save abiodun0/883df106eb68ec0d78b5c80cbde16747 to your computer and use it in GitHub Desktop.
Save abiodun0/883df106eb68ec0d78b5c80cbde16747 to your computer and use it in GitHub Desktop.
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