-
Notifications
You must be signed in to change notification settings - Fork 772
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
base: main
Are you sure you want to change the base?
Rule/date time diff #1463
Conversation
Signed-off-by: Henrique Moody <[email protected]>
library/Rules/DateTimeDiff.php
Outdated
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', | ||
}; | ||
} | ||
} |
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.
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
private function isDateIntervalType(string $age): bool | ||
{ | ||
return in_array($age, array_keys(get_object_vars((new DateInterval('P1Y'))))); | ||
} |
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.
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?
@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! |
Codecov ReportAttention: Patch coverage is
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. |
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. 👍