-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
assert: allow comparing time.Time #1149
Conversation
54276bb
to
34f4b86
Compare
Had to fiddle a bit with build tags to get this working across versions. Nw tests pass locally for me with both a new (1.17.6) and old (1.14.15). Looks like CI is fine as well. |
timeObj1 = obj1Value.Convert(timeType).Interface().(time.Time) | ||
} |
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.
Why are we converting to timeType
(i.e. time
), then interface, then back to time?
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.
Convert()
returns a reflect.Value
, Interface()
takes us out of the reflection wrappers, and then finally we do a type assertion. It looks a bit convoluted, but it's all necessary!
34f4b86
to
5dc4a0a
Compare
Rebased, and added doc comments. Assumed you meant 1.16, as that's what's holding up the build tag stuff. |
5dc4a0a
to
53049ef
Compare
Okay, this is a bit awkward... |
Nvm, got it working. Let's go 🚀 |
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.
Thank you :)
Summary
Add support for comparing
time>Time
and custom types derived from it.Changes
When comparing types, see if we're comparing
time.Time
, or a custom type based ontime.Time
. If that's the case, compare their Unix timestamps, with the smallest possible resolution.Motivation
This now allows sticking a
time.Time
intoassert.Greater
andassert.Less
, which is nice. Time stamps have a natural ordering, so I'd expect this to work.