-
Notifications
You must be signed in to change notification settings - Fork 211
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
Decode: validate dates #622
Decode: validate dates #622
Conversation
I have some local changes adding similar calls to |
@pelletier how should I add test cases for covering 9d45398? I tried adding an additional case in {
desc: `invalid local date-time`,
data: `A = "2021-03-40T23:59:00"`,
msg: `invalid local date-time`,
}, doesn't seem to return the expected error. |
Sorry for the late reply! Commenting on the general approach taken: this looks like a very expensive approach. Given we have year/month/day already parsed, can we just have a validation step that does not perform allocations? |
As I understand it, this error tester is expecting an error to be returned, but one isn't being returned even though I'm feeding it a test case with an invalid date. |
Given the test makes a call to |
I was wondering about that, it seemed to me that validating day counts for each month reinvents the wheel a bit. It's definitely easier for time and month validation, though. What approach do you suggest for validating days – perhaps a map that maps month-number to its day count? Or, as I'm typing this I'm thinking this might be an appropriate use for a |
In that kind of scenario I usually defer to the Go stdlib implementation: They use a simple table lookup. As far as I know those methods are not publicly accessible. We could use |
9d45398
to
1b6184f
Compare
Woops, looks like there are some new tests upstream for handling what constitutes a valid time. @pelletier do you think it's better to keep changes introduced in #614 (here) where each element of a time datum is checked as it's parsed, or is it better to check the whole time datum with the |
I have no preference on the approach. However the existing tests provide more precise error messages to the user, which is a good property to have. As long as validation makes it clear to the user what the problem is, I don’t have a preference.
|
1b6184f
to
700fbd8
Compare
Ok, in that case I've removed my redundant time validation 🙂 |
Copies date checking functionality from go.time.go to verify that the provided date is indeed valid for a given year, accounting for leap years. Resolves: part of pelletier#613
Resolves: part of pelletier#613
700fbd8
to
1f96179
Compare
Ready for review now |
Also the resolution for this was that I was mistakenly quoting the date value |
Resolves: part of pelletier#613
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.
Thanks for working on this! Added two small comments on the change. Seems like the coverage went down, so it should mean that some code paths are not covered by the tests -- we really try to not bring down test coverage percentage. It's not a perfect metric, but I found it to mostly accomplish its goal.
Simplifies a return and reduces dependency on `time` library. Resolves: pelletier#622 (comment) and pelletier#622 (comment)
Resolved in 602925b – thanks for the feedback, I'm still relatively new to Go so getting these tips is really helping my learning 😁. re: code coverage, are the testgen cases run in CI too now that you've added the skip statements to the still-breaking cases? |
nvm, I checked and it is. I would guess that the coverage drop is because of the size of the stuff copied over from |
Caused a drop in coverage because it added unreachable lines.
Good call with the coverage comment, I looked deeper and found some unreachable code in a redundant date validity check 🙂. Should be good for re-review now @pelletier. |
Looking good, merged! Thank you! |
My pleasure! If it's not too much trouble, could you put a |
No problem, done. I bet they only look at PRs merged in the main branch, which v2 is not quite ready for that yet. |
Ah, good point. Thanks! |
Issue: #613
Constructs a datestring with RFC3339 formatting using the parsed date
values, then attempts to call
time.Parse()
on it, which returns anon-nil error if datetime string was invalid or
time
's parsing ofthe string failed.
Fixes
go test -tags testsuite -run TestTOMLTest_Invalid_Datetime_ImpossibleDate
failure.