-
Notifications
You must be signed in to change notification settings - Fork 61
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
Add isLocalDate to CharSequenceConstraint #283
Conversation
Any updates on this? |
@@ -182,6 +185,22 @@ private <U> CharSequenceConstraint<T, E> isValidRepresentationOf( | |||
return this; | |||
} | |||
|
|||
/** | |||
* @since 0.11.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.12.0
* @since 0.11.3 | ||
*/ | ||
public CharSequenceConstraint<T, E> isLocalDate() { | ||
return this.isValidLocalDate("yyyy-MM-dd"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uuuu-MM-dd
private CharSequenceConstraint<T, E> isValidLocalDate(String pattern) { | ||
this.predicates().add(ConstraintPredicate.of(x -> { | ||
try { | ||
LocalDate.parse(x, DateTimeFormatter.ofPattern(pattern)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DateTimeFormatter.ofPattern(pattern, locale).withResolverStyle(ResolverStyle.STRICT)
@@ -238,6 +257,20 @@ public CharSequenceConstraint<T, E> isBigDecimal() { | |||
return this.isValidRepresentationOf(BigDecimal::new, CHAR_SEQUENCE_BIGDECIMAL); | |||
} | |||
|
|||
/** | |||
* @since 0.11.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.12.0
} | ||
|
||
/** | ||
* @since 0.11.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.12.0
/** | ||
* @since 0.11.3 | ||
*/ | ||
public CharSequenceConstraint<T, E> isLocalDate() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isIsoLocalDate
/** | ||
* @since 0.11.3 | ||
*/ | ||
private CharSequenceConstraint<T, E> isValidLocalDate(String pattern) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isValidLocalDate(String pattern, Locale locale)
@ffroliva |
@ffroliva Thanks for your contribution! |
It was my pleasure! |
Hi this pull request addes isLocalDate validation in CharSequenceConstraint. This validates if a given string is in ISO format or in a given pattern format.