Skip to content

Commit b7e20ba

Browse files
committed
* All date comparison validators now validate as false when the comparison target dates values are NOT dates instead of throwing an exception.
1 parent 3b4ff8c commit b7e20ba

File tree

6 files changed

+69
-17
lines changed

6 files changed

+69
-17
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
* New ColdBox 7 delegate: `Validatable@cbValidation` which can be used to make objects validatable
1515
* New validators: `notSameAs, notSameAsNoCase`
1616

17+
### Changed
18+
19+
* All date comparison validators now validate as `false` when the comparison target dates values are NOT dates instead of throwing an exception.
20+
1721
----
1822

1923
## [4.0.0] => 2022-OCT-10

models/validators/AfterOrEqualValidator.cfc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,22 @@ component extends="BaseValidator" accessors="true" singleton {
3838
if ( isNull( arguments.targetValue ) || isNullOrEmpty( arguments.targetValue ) ) {
3939
return true;
4040
}
41-
// If not a date, throw it
41+
42+
// If not a date, invalide it
4243
if ( !isDate( arguments.targetValue ) ) {
43-
throw(
44-
message = "The date you sent is an invalid date [#arguments.targetValue#]",
45-
type = "InvalidValidationData"
44+
validationResult.addError(
45+
validationResult.newError(
46+
argumentCollection = {
47+
message : "The '#arguments.targetValue#' is not a valid date, so we cannot compare them.",
48+
field : arguments.field,
49+
validationType : getName(),
50+
rejectedValue : ( arguments.targetValue ),
51+
validationData : arguments.validationData,
52+
errorMetadata : { "afterOrEqual" : arguments.targetValue }
53+
}
54+
)
4655
);
56+
return false;
4757
}
4858

4959
// The compare value is set or it can be another field

models/validators/AfterValidator.cfc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,22 @@ component extends="BaseValidator" accessors="true" singleton {
3838
if ( isNull( arguments.targetValue ) || isNullOrEmpty( arguments.targetValue ) ) {
3939
return true;
4040
}
41-
// If target is not a date, throw it
41+
42+
// If target is not a date, invalidate it
4243
if ( !isDate( arguments.targetValue ) ) {
43-
throw(
44-
message = "The date you sent is an invalid date [#arguments.targetValue#]",
45-
type = "InvalidValidationData"
44+
validationResult.addError(
45+
validationResult.newError(
46+
argumentCollection = {
47+
message : "The '#arguments.targetValue#' is not a valid date, so we cannot compare them.",
48+
field : arguments.field,
49+
validationType : getName(),
50+
rejectedValue : ( arguments.targetValue ),
51+
validationData : arguments.validationData,
52+
errorMetadata : { "afterOrEqual" : arguments.targetValue }
53+
}
54+
)
4655
);
56+
return false;
4757
}
4858

4959
// The compare value is set or it can be another field

models/validators/BeforeOrEqualValidator.cfc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,19 @@ component extends="BaseValidator" accessors="true" singleton {
4040
}
4141
// If not a date, throw it
4242
if ( !isDate( arguments.targetValue ) ) {
43-
throw(
44-
message = "The date you sent is an invalid date [#arguments.targetValue#]",
45-
type = "InvalidValidationData"
43+
validationResult.addError(
44+
validationResult.newError(
45+
argumentCollection = {
46+
message : "The '#arguments.targetValue#' is not a valid date, so we cannot compare them.",
47+
field : arguments.field,
48+
validationType : getName(),
49+
rejectedValue : ( arguments.targetValue ),
50+
validationData : arguments.validationData,
51+
errorMetadata : { "afterOrEqual" : arguments.targetValue }
52+
}
53+
)
4654
);
55+
return false;
4756
}
4857

4958
// The compare value is set or it can be another field

models/validators/BeforeValidator.cfc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,19 @@ component extends="BaseValidator" accessors="true" singleton {
4040
}
4141
// If not a date, throw it
4242
if ( !isDate( arguments.targetValue ) ) {
43-
throw(
44-
message = "The date you sent is an invalid date [#arguments.targetValue#]",
45-
type = "InvalidValidationData"
43+
validationResult.addError(
44+
validationResult.newError(
45+
argumentCollection = {
46+
message : "The '#arguments.targetValue#' is not a valid date, so we cannot compare them.",
47+
field : arguments.field,
48+
validationType : getName(),
49+
rejectedValue : ( arguments.targetValue ),
50+
validationData : arguments.validationData,
51+
errorMetadata : { "afterOrEqual" : arguments.targetValue }
52+
}
53+
)
4654
);
55+
return false;
4756
}
4857

4958
// The compare value is set or it can be another field

models/validators/DateEqualsValidator.cfc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,22 @@ component extends="BaseValidator" accessors="true" singleton {
3838
if ( isNull( arguments.targetValue ) || isNullOrEmpty( arguments.targetValue ) ) {
3939
return true;
4040
}
41+
4142
// If not a date, throw it
4243
if ( !isDate( arguments.targetValue ) ) {
43-
throw(
44-
message = "The date you sent is an invalid date [#arguments.targetValue#]",
45-
type = "InvalidValidationData"
44+
validationResult.addError(
45+
validationResult.newError(
46+
argumentCollection = {
47+
message : "The '#arguments.targetValue#' is not a valid date, so we cannot compare them.",
48+
field : arguments.field,
49+
validationType : getName(),
50+
rejectedValue : ( arguments.targetValue ),
51+
validationData : arguments.validationData,
52+
errorMetadata : { "afterOrEqual" : arguments.targetValue }
53+
}
54+
)
4655
);
56+
return false;
4757
}
4858

4959
// The compare value is set or it can be another field

0 commit comments

Comments
 (0)