Skip to content
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

Support constraints on date/time types #37

Closed
making opened this issue Jan 14, 2020 · 11 comments · Fixed by #195
Closed

Support constraints on date/time types #37

making opened this issue Jan 14, 2020 · 11 comments · Fixed by #195
Labels
enhancement New feature or request
Milestone

Comments

@making
Copy link
Owner

making commented Jan 14, 2020

Derived from #22 (comment)

@making making added the enhancement New feature or request label Jan 14, 2020
@making
Copy link
Owner Author

making commented Jan 14, 2020

If the expected feature is validating if the given value is in a range, I would provide constraints on Comparable rather than constraints on date/time types as supporting date/time is a bit tough (so many classes to support).

@making
Copy link
Owner Author

making commented Jan 14, 2020

any comments would be appreciated

@night-crawler
Copy link

I would provide constraints on Comparable rather than constraints on date/time types

I'm just curious, will it help to supersede Number-alike constraint implementations, like BigIntegerConstraint, and other <Number>Constraint?

@making
Copy link
Owner Author

making commented Jan 15, 2020

Good point. It could replace existing constraints. I need investigations.

@making
Copy link
Owner Author

making commented Jan 26, 2020

I just noticed that most classes in JSR-310 did not implement Comparable.
I'll leave this issue open but this feature will not be included in 0.3.

@making
Copy link
Owner Author

making commented Jan 26, 2020

I just noticed that most classes in JSR-310 did not implement Comparable.

This is not true. But it is not as simple as expected since LocalDateTime implements ChronoLocalDateTime<LocalDate> which extends Comparable<ChronoLocalDateTime<?>>.

@making making added this to the 0.9.0 milestone Jul 2, 2021
@making making removed this from the 0.9.0 milestone Sep 21, 2021
@ffroliva
Copy link
Contributor

I think that adding validation to LocalDate and LocalDateTime to cover before, after and between dates would be a good starting point. More complex scenarios could come later or even could be implemented with a custom validation.

@DiegoKrupitza
Copy link
Contributor

DiegoKrupitza commented Dec 27, 2021

I think that adding validation to LocalDate and LocalDateTime to cover before, after and between dates would be a good starting point. More complex scenarios could come later or even could be implemented with a custom validation.

I am right now working on this feature. The current approach is to have the following:

temporalYAVI drawio

The base classes will implement common logic. It is basically has the same hierarchy as java.time (see here)

@DiegoKrupitza
Copy link
Contributor

Update: I introduced a second layer so comparable temporals do not have to implement the same methods over and over again.
TemporalConstraintsJAVI

@ffroliva
Copy link
Contributor

ffroliva commented Dec 27, 2021 via email

DiegoKrupitza added a commit to DiegoKrupitza/yavi that referenced this issue Dec 27, 2021
It is now possible to add constraints on `java.time.LocalDate`, `java.time.LocalDateTime` and `java.time.ZonedDateTime`. Constraints that are currently available are `after(...)`, `before(...)`, `between(...)`, `leapYear(...)` and `zone(...)`. For further development the Temporal constraints are split into a hierarchy. The hierarchy is bound to the `java.time` hierarchy.

Closes making#37
@DiegoKrupitza
Copy link
Contributor

My understanding is that you need a extra field which your before and after method would use to compare against. How are you doind that?

On Mon, 27 Dec 2021, 20:42 Diego Krupitza, @.> wrote: Update: I introduced a second layer so comparable temporals do not have to implement the same methods over and over again. [image: TemporalConstraintsJAVI] https://user-images.githubusercontent.com/25965672/147505921-1b33007e-ed9e-4739-a26a-51c42dcfaa5d.png — Reply to this email directly, view it on GitHub <#37 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF67VG7VYIHTM2U2BUKI5KDUTDFUVANCNFSM4KGUJDVA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you commented.Message ID: @.>

The before and after method does include a parameter which is checked on. Further details can be seen in #195

@making making added this to the 0.10.0 milestone Dec 28, 2021
making pushed a commit that referenced this issue Dec 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants