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

Fix - user not able to save last enable date of birth #26271

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Changes from all commits
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
21 changes: 13 additions & 8 deletions src/libs/ValidationUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {subYears, addYears, startOfDay, endOfMonth, isAfter, isBefore, isValid, isWithinInterval, isSameDay, format} from 'date-fns';
import {subYears, addYears, startOfDay, endOfMonth, parse, isAfter, isBefore, isValid, isWithinInterval, isSameDay, format} from 'date-fns';
import _ from 'underscore';
import {URL_REGEX_WITH_REQUIRED_PROTOCOL} from 'expensify-common/lib/Url';
import {parsePhoneNumber} from 'awesome-phonenumber';
Expand Down Expand Up @@ -233,19 +233,24 @@ function meetsMaximumAgeRequirement(date) {
*/
function getAgeRequirementError(date, minimumAge, maximumAge) {
const currentDate = startOfDay(new Date());
const recentDate = subYears(currentDate, minimumAge);
const longAgoDate = subYears(currentDate, maximumAge);
const testDate = new Date(date);
const testDate = parse(date, CONST.DATE.FNS_FORMAT_STRING, currentDate);

if (!isValid(testDate)) {
return 'common.error.dateInvalid';
}
if (isWithinInterval(testDate, {start: longAgoDate, end: recentDate})) {

const maximalDate = subYears(currentDate, minimumAge);
const minimalDate = subYears(currentDate, maximumAge);

if (isWithinInterval(testDate, {start: minimalDate, end: maximalDate})) {
return '';
}
if (isSameDay(testDate, recentDate) || isAfter(testDate, recentDate)) {
return ['privatePersonalDetails.error.dateShouldBeBefore', {dateString: format(recentDate, CONST.DATE.FNS_FORMAT_STRING)}];

if (isSameDay(testDate, maximalDate) || isAfter(testDate, maximalDate)) {
return ['privatePersonalDetails.error.dateShouldBeBefore', {dateString: format(maximalDate, CONST.DATE.FNS_FORMAT_STRING)}];
}
return ['privatePersonalDetails.error.dateShouldBeAfter', {dateString: format(longAgoDate, CONST.DATE.FNS_FORMAT_STRING)}];

return ['privatePersonalDetails.error.dateShouldBeAfter', {dateString: format(minimalDate, CONST.DATE.FNS_FORMAT_STRING)}];
}

/**
Expand Down
Loading