@@ -1047,6 +1047,61 @@ describe('Date Utilities', () => {
10471047 expect ( isRelativeDateFilterValue ( '-3d' ) ) . toBeTruthy ( ) ;
10481048 expect ( isRelativeDateFilterValue ( '-0d' ) ) . toBeTruthy ( ) ;
10491049 } ) ;
1050+
1051+ test ( 'relaxedMatch=true, bad input' , ( ) => {
1052+ expect ( isRelativeDateFilterValue ( '' , true ) ) . toBeFalsy ( ) ;
1053+ expect ( isRelativeDateFilterValue ( ' ' , true ) ) . toBeFalsy ( ) ;
1054+ expect ( isRelativeDateFilterValue ( '-D' , true ) ) . toBeFalsy ( ) ;
1055+ expect ( isRelativeDateFilterValue ( 'ad' , true ) ) . toBeFalsy ( ) ;
1056+ expect ( isRelativeDateFilterValue ( 'a1' , true ) ) . toBeFalsy ( ) ;
1057+ expect ( isRelativeDateFilterValue ( '1dd' , true ) ) . toBeFalsy ( ) ;
1058+ } ) ;
1059+
1060+ test ( 'relaxedMatch=true allows incomplete values ending with d' , ( ) => {
1061+ expect ( isRelativeDateFilterValue ( '3d' , true ) ) . toBeTruthy ( ) ;
1062+ expect ( isRelativeDateFilterValue ( '0d' , true ) ) . toBeTruthy ( ) ;
1063+ expect ( isRelativeDateFilterValue ( '300d' , true ) ) . toBeTruthy ( ) ;
1064+ expect ( isRelativeDateFilterValue ( 'd' , true ) ) . toBeTruthy ( ) ;
1065+ } ) ;
1066+
1067+ test ( 'relaxedMatch=true allows values starting with sign' , ( ) => {
1068+ expect ( isRelativeDateFilterValue ( '+3' , true ) ) . toBeTruthy ( ) ;
1069+ expect ( isRelativeDateFilterValue ( '-3' , true ) ) . toBeTruthy ( ) ;
1070+ expect ( isRelativeDateFilterValue ( '+0' , true ) ) . toBeTruthy ( ) ;
1071+ expect ( isRelativeDateFilterValue ( '-0' , true ) ) . toBeTruthy ( ) ;
1072+ expect ( isRelativeDateFilterValue ( '+300' , true ) ) . toBeTruthy ( ) ;
1073+ expect ( isRelativeDateFilterValue ( '-300' , true ) ) . toBeTruthy ( ) ;
1074+ expect ( isRelativeDateFilterValue ( '+d' , true ) ) . toBeTruthy ( ) ;
1075+ expect ( isRelativeDateFilterValue ( '-d' , true ) ) . toBeTruthy ( ) ;
1076+ } ) ;
1077+
1078+ test ( 'relaxedMatch=true allows numbers with optional d' , ( ) => {
1079+ expect ( isRelativeDateFilterValue ( '3' , true ) ) . toBeTruthy ( ) ;
1080+ expect ( isRelativeDateFilterValue ( '0' , true ) ) . toBeTruthy ( ) ;
1081+ expect ( isRelativeDateFilterValue ( '300' , true ) ) . toBeTruthy ( ) ;
1082+ } ) ;
1083+
1084+ test ( 'relaxedMatch=true still accepts strict format' , ( ) => {
1085+ expect ( isRelativeDateFilterValue ( '+3d' , true ) ) . toBeTruthy ( ) ;
1086+ expect ( isRelativeDateFilterValue ( '+300d' , true ) ) . toBeTruthy ( ) ;
1087+ expect ( isRelativeDateFilterValue ( '-3d' , true ) ) . toBeTruthy ( ) ;
1088+ expect ( isRelativeDateFilterValue ( '-0d' , true ) ) . toBeTruthy ( ) ;
1089+ } ) ;
1090+
1091+ test ( 'relaxedMatch=true still rejects invalid values' , ( ) => {
1092+ expect ( isRelativeDateFilterValue ( '++3d' , true ) ) . toBeFalsy ( ) ;
1093+ expect ( isRelativeDateFilterValue ( '2022-04-19' , true ) ) . toBeFalsy ( ) ;
1094+ expect ( isRelativeDateFilterValue ( 'abc' , true ) ) . toBeFalsy ( ) ;
1095+ expect ( isRelativeDateFilterValue ( 'd3' , true ) ) . toBeFalsy ( ) ;
1096+ } ) ;
1097+
1098+ test ( 'relaxedMatch=false uses strict validation' , ( ) => {
1099+ expect ( isRelativeDateFilterValue ( '3d' , false ) ) . toBeFalsy ( ) ;
1100+ expect ( isRelativeDateFilterValue ( '+3' , false ) ) . toBeFalsy ( ) ;
1101+ expect ( isRelativeDateFilterValue ( '3' , false ) ) . toBeFalsy ( ) ;
1102+ expect ( isRelativeDateFilterValue ( '+3d' , false ) ) . toBeTruthy ( ) ;
1103+ expect ( isRelativeDateFilterValue ( '-3d' , false ) ) . toBeTruthy ( ) ;
1104+ } ) ;
10501105 } ) ;
10511106
10521107 describe ( 'getParsedRelativeDateStr' , ( ) => {
0 commit comments