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

Use (time.Time).Equal for time objects #1011

Closed
wants to merge 2 commits into from

Conversation

gfelixc
Copy link

@gfelixc gfelixc commented Oct 17, 2020

Summary

Use built-in Equal method when compare time.Time objects

Changes

When use Equal, try to cast given objects into time.Time and uses (time.Time).Equal in case of true

Motivation

See #1010

Related issues

Closes #1010

Breaking change


p, ok := o.(*time.Time)
if ok {
return *p, true
Copy link

Choose a reason for hiding this comment

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

p could be a nil pointer, please check that p != nil before dereferencing it.

@leoleoasd
Copy link

Does the exact same thing with #979.
#979 is reverted shortly after merge, because, as #984 mentions, this only fixes comparing between time. a struct containing time still cannot be compared. #985 tried to fix this by creating something like reflect.DeepEqual and call time.Time.Equal when needed, but used unsafe pointers.

@dolmen dolmen added pkg-assert Change related to package testify/assert type-Time Related to type time.Time or the time package assert.EqualValues About equality labels Oct 31, 2023
@brackendawson
Copy link
Collaborator

Earlier duplicate of #1464

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assert.EqualValues About equality pkg-assert Change related to package testify/assert type-Time Related to type time.Time or the time package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Testify assert.Equal between two times doesn't work same as (time.Time).Equal.
5 participants