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

DateDiff rule #1462

Open
gvieiragoulart opened this issue Jul 3, 2024 · 8 comments · May be fixed by #1463
Open

DateDiff rule #1462

gvieiragoulart opened this issue Jul 3, 2024 · 8 comments · May be fixed by #1463

Comments

@gvieiragoulart
Copy link

Hey guys, I'm new in this project and I want to contribute by doing the DateDiff rule. But I noticed that we don't have any of differentiation rule.

What do you guys think about creating a new Core rule to help these differentiation rules?

@alganet
Copy link
Member

alganet commented Jul 3, 2024

Hi @gvieiragoulart!

For a lot of use cases, you can use v::between(), v::greaterThan() and so on with DateTime instances. See the CanCompareValues trait. I know this is not a full diff that can assert values on the intervals, but it goes a long way.

We also have the MinAge and MaxAge rules, which are kind of a date diff validation, but only for the year part. These provide some scalar based diff, not only boolean comparison. They could be better (microsecond or nanosecond resolution).

Maybe none of these fit what you need. If that's the case, let us know! Maybe draft an example of what this new validator would look like, what do you think?

I think there are some good improvements that could be done over this area. If you want to work on it, you have my blessing!

@henriquemoody
Copy link
Member

Hi there!

I've started working on that rule, but due to a succession of major life events, I couldn't complete it for version 3.0.

henriquemoody@9e631a8

Is that what you were looking for, @gvieiragoulart? I'd be happy if anyone picks this up.

@gvieiragoulart
Copy link
Author

Hey @henriquemoody @alganet !

If I could pick this task I would be really happy to try complete but it seems to me that you have done almost the entire work. What do you see that we have to improve?

@henriquemoody
Copy link
Member

@gvieiragoulart, I don't really know what needs to improve. I know the tests are not passing, though. I won't be working on it any time soon, so if you want to pick it up, I'd be very happy with it!

@alganet
Copy link
Member

alganet commented Jul 6, 2024

@gvieiragoulart I have some idea of what the next steps should be:

  • Finish the DateDiffException which seems to be missing.
  • Complete the tests with all kinds of diff examples
  • Change the *Age validators to reuse the new DateDiff ones internally. I would also mark them as deprecated to be removed in a future version (WDYT @henriquemoody?)
  • Adjust the docs to reflect the changes (i.e. if we deprecate something, mark as deprecated on that validator markdown file).

PHP also has the DateInterval and DatePeriod classes. One of the core goals of Respect\Validation is to provide tools that fit seamlessly with PHP builtins, so it might be a good idea to add support for them. This should probably go as a separate PR though.

Let us know if you have any other questions, if anything doesn't make sense or require more clarification!

@gvieiragoulart
Copy link
Author

@alganet

I didn't find any Age validator on the code to reuse :( i think i missed something.

@gvieiragoulart gvieiragoulart linked a pull request Jul 14, 2024 that will close this issue
@gvieiragoulart
Copy link
Author

Hey guys, I believe that I completed the feature.

@alganet I didn't use those validators because the type is specific to the DateInterval types, so I created another validation.

PR here #1463

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants