Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated logic to Not allow future date as incorporation date #5939

Merged
merged 6 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/libs/ValidationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ function isValidDate(date) {
return testDate.isValid() && testDate.isBetween(pastDate, futureDate);
}

/**
* Validate that date entered isn't a future date.
*
* @param {String|Date} date
* @returns {Boolean} true if valid
*/
function isValidPastDate(date) {
if (!date) {
return false;
}

const pastDate = moment().subtract(1000, 'years');
const currentDate = moment();
const testDate = moment(date).startOf('day');
puneetlath marked this conversation as resolved.
Show resolved Hide resolved
return testDate.isValid() && testDate.isBetween(pastDate, currentDate);
}

/**
* Used to validate a value that is "required".
*
Expand Down Expand Up @@ -216,6 +233,7 @@ export {
meetsAgeRequirements,
isValidAddress,
isValidDate,
isValidPastDate,
isValidSecurityCode,
isValidExpirationDate,
isValidDebitCard,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ReimbursementAccount/CompanyStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import TextLink from '../../components/TextLink';
import StatePicker from '../../components/StatePicker';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import {
isValidDate, isRequiredFulfilled, isValidURL, isValidPhoneWithSpecialChars,
isValidPastDate, isRequiredFulfilled, isValidURL, isValidPhoneWithSpecialChars,
} from '../../libs/ValidationUtils';
import compose from '../../libs/compose';
import ONYXKEYS from '../../ONYXKEYS';
Expand Down Expand Up @@ -153,7 +153,7 @@ class CompanyStep extends React.Component {
errors.companyTaxID = true;
}

if (!isValidDate(this.state.incorporationDate)) {
if (!isValidPastDate(this.state.incorporationDate)) {
puneetlath marked this conversation as resolved.
Show resolved Hide resolved
errors.incorporationDate = true;
}

Expand Down