-
Notifications
You must be signed in to change notification settings - Fork 298
feature: detect time/date out of bounds in time-date rule #1370
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
Conversation
This a naive approach that may require some iterations. |
Switching back to draft to code the suggestion made during the code review. It can be reviewed anyway |
d4a70e2
to
bffa778
Compare
ec1930a
to
b45d390
Compare
Here are the change I made since the last time I worked on it: I'm now validating arguments with multiple rules:
There are some other changes, but they are the main ones. Please review again, thanks Let me know if you think I should adapt the confidence level of each error reporting. |
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've some remarks/questions but LGTM
I refactored code, it should be clearer I think, thanks @chavacava |
I feel like, I screw up my PR by resolving conflicts 😅 |
dates are checked with the following rules: - no validation for year - arguments cannot be negative - arguments cannot use an explicit plus sign - month must be between 1 and 12 - day must be between 1 and 31 for January, March, May, July, August, October, December - day must be between 1 and 30 for April, June, September, November - day must be between 1 and 28 for February, or 29 for leap years - hour must be between 0 and 23 - minute must be between 0 and 59 - second must be between 0 and 59 (and 60 for leap seconds) - nanosecond must be between 0 and 999999999, because otherwise you can use a second
It can be reviewed again. |
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.
Pull Request Overview
Adds validation for out-of-bounds values in calls to time.Date
, ensuring month, day, hour, minute, second, and nanosecond arguments fall within their legal ranges.
- Introduces a new test file (
time_date_out_of_bounds.go
) with cases covering zero, negative, swapped, and extreme values. - Updates the
TimeDateRule
implementation to track each argument’s boundaries, refactors literal parsing to returnint64
, and adds unary-sign handling. - Adjusts existing decimal‐literal tests and updates documentation/examples in
RULES_DESCRIPTIONS.md
.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
testdata/time_date_out_of_bounds.go | New var block with test cases for out‐of‐bounds dates |
testdata/time_date_decimal_literal.go | Replaces old examples with an expression case using i and j |
test/time_date_test.go | Registers the new out‐of‐bounds test suite |
rule/time_date.go | Implements argument boundary checks and refactors parsing |
RULES_DESCRIPTIONS.md | Expands rule examples and adds detailed <details> |
Comments suppressed due to low confidence (1)
testdata/time_date_decimal_literal.go:91
- The assignment
i = 4
is invalid at package scope inside a var block. You need to declare these asvar i = 4
(andvar j = 1
) or move them into a function scope.
i = 4
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.
LGTM
Left a few minor comments.
Co-authored-by: Oleksandr Redko <[email protected]>
Thanks @alexandear I have applied the changes you suggested |
dates are checked with the following rules:
Fixes #1369