@@ -130,12 +130,8 @@ const evaluate = (func, args, ret, tokenize) => {
130
130
const { sanitizeJavaScriptCode } = navFormioUtils ;
131
131
132
132
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 ;
139
135
} ;
140
136
141
137
const isAgeBetween = ( ageInterval , fnrKey , submission = { } , pointInTime = moment ( ) ) => {
@@ -148,11 +144,18 @@ const isAgeBetween = (ageInterval, fnrKey, submission = {}, pointInTime = moment
148
144
} ;
149
145
150
146
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 = { } ) => {
151
155
const value = Utils . getValue ( submission , fnrKey ) ;
152
156
if ( value && fnrvalidator . fnr ( value . trim ( ) ) . status === 'valid' ) {
153
157
const birthDateStr = value . substring ( 0 , 6 ) ;
154
- const birthDate = moment ( birthDateStr , 'DDMMYY' ) ;
155
- return pointInTime . diff ( birthDate , 'years' , false ) ;
158
+ return moment ( birthDateStr , 'DDMMYY' ) ;
156
159
}
157
160
return undefined ;
158
161
} ;
0 commit comments