Skip to content

Commit c64093a

Browse files
committed
common function extracts birth date from ssn
1 parent e15dbdc commit c64093a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

packages/shared-components/src/formio/overrides/utils-overrides/utils-overrides.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,8 @@ const evaluate = (func, args, ret, tokenize) => {
130130
const { sanitizeJavaScriptCode } = navFormioUtils;
131131

132132
const isBornBeforeYear = (year, fnrKey, submission = {}) => {
133-
const value = Utils.getValue(submission, fnrKey);
134-
if (value && fnrvalidator.fnr(value.trim()).status === 'valid') {
135-
const birthDateStr = value.substring(0, 6);
136-
return moment(birthDateStr, 'DDMMYY').year() < year;
137-
}
138-
return false;
133+
const birthDate = getBirthDate(fnrKey, submission);
134+
return birthDate ? birthDate.year() < year : false;
139135
};
140136

141137
const isAgeBetween = (ageInterval, fnrKey, submission = {}, pointInTime = moment()) => {
@@ -148,11 +144,18 @@ const isAgeBetween = (ageInterval, fnrKey, submission = {}, pointInTime = moment
148144
};
149145

150146
const getAge = (fnrKey, submission = {}, pointInTime = moment()) => {
147+
const birthDate = getBirthDate(fnrKey, submission);
148+
if (birthDate) {
149+
return pointInTime.diff(birthDate, 'years', false);
150+
}
151+
return undefined;
152+
};
153+
154+
const getBirthDate = (fnrKey, submission = {}) => {
151155
const value = Utils.getValue(submission, fnrKey);
152156
if (value && fnrvalidator.fnr(value.trim()).status === 'valid') {
153157
const birthDateStr = value.substring(0, 6);
154-
const birthDate = moment(birthDateStr, 'DDMMYY');
155-
return pointInTime.diff(birthDate, 'years', false);
158+
return moment(birthDateStr, 'DDMMYY');
156159
}
157160
return undefined;
158161
};

0 commit comments

Comments
 (0)