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

Rule/date time diff #1463

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

gvieiragoulart
Copy link

Resolves #1462


What?

This PR introduces a new validation rule, DateTimeDiff wich validates the difference of date/time against a specific rule.

The $type argument on our construct should follow PHP's DateInterval properties. So we can use types such as year, months,days,full days,hours,minutes,seconds,microseconds.


Note: This is my first PR in a relatively large open-source project, so if I've done anything incorrectly, please let me know. 👍

@gvieiragoulart gvieiragoulart mentioned this pull request Jul 14, 2024
Comment on lines 139 to 152
private function getTranslatedType(string $type): string
{
return match ($type) {
'y' => 'years',
'm' => 'months',
'd' => 'days',
'days' => 'full days',
'h' => 'hours',
'i' => 'minutes',
's' => 'seconds',
'f' => 'microseconds',
};
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are going to use this, I believe that we can improve to a Enum file. I didn't create because the project don't have any

Comment on lines +70 to +73
private function isDateIntervalType(string $age): bool
{
return in_array($age, array_keys(get_object_vars((new DateInterval('P1Y')))));
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this seems weird, but i wanted to use those DateInterval vars. what do you guys think about it? How do we can improve this validation?

@alganet
Copy link
Member

alganet commented Jul 15, 2024

@gvieiragoulart I approved the CI run. There are some static analysis checks you'll need to fix before we can merge this!

I'll keep an eye here to approve the CI run again as soon as you fix them, and once it passes, I'll do a full review!

Copy link

codecov bot commented Jul 15, 2024

Codecov Report

Attention: Patch coverage is 94.11765% with 5 lines in your changes missing coverage. Please review.

Project coverage is 97.28%. Comparing base (d7dc0f2) to head (906f722).
Report is 3 commits behind head on main.

Files Patch % Lines
library/Rules/DateTimeDiff.php 93.22% 4 Missing ⚠️
library/Helpers/CanExtractRules.php 93.75% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1463      +/-   ##
============================================
+ Coverage     96.20%   97.28%   +1.07%     
- Complexity      917      950      +33     
============================================
  Files           199      200       +1     
  Lines          2109     2206      +97     
============================================
+ Hits           2029     2146     +117     
+ Misses           80       60      -20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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 this pull request may close these issues.

DateDiff rule
3 participants