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

Same time values in same timezone are not equal #1461

Closed
gabriel-vasile opened this issue Aug 25, 2023 · 1 comment · Fixed by #1464
Closed

Same time values in same timezone are not equal #1461

gabriel-vasile opened this issue Aug 25, 2023 · 1 comment · Fixed by #1464
Labels
assert.EqualValues About equality bug pkg-assert Change related to package testify/assert

Comments

@gabriel-vasile
Copy link

https://go.dev/play/p/hHHtLV8pnt0?v=goprev

func TestAAAA(t *testing.T) {
	t1 := time.Now()
	// Create a copy of the same time using the same local timezone.
	t2 := t1.In(time.Local)
	assert.Equal(t, t1, t2)
}
=== RUN   TestAAAA
    prog_test.go:16: 
        	Error Trace:	/tmp/sandbox2123072853/prog_test.go:16
        	Error:      	Not equal: 
        	            	expected: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.Local)
        	            	actual  : time.Date(2009, time.November, 10, 23, 0, 0, 0, time.Local)
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1,2 +1,2 @@
        	            	-(time.Time) 2009-11-10 23:00:00 +0000 UTC m=+0.000000001
        	            	+(time.Time) 2009-11-10 23:00:00 +0000 UTC
        	            	 
        	Test:       	TestAAAA

In addition to this, I think it would be good if same time instants with different timezones would be equal. In my use case, it would help if time was compared using time.Equal.

@dolmen dolmen added bug pkg-assert Change related to package testify/assert assert.EqualValues About equality labels Oct 10, 2023
@dolmen
Copy link
Collaborator

dolmen commented Oct 10, 2023

Good catch. Thanks for the short test case.

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

Successfully merging a pull request may close this issue.

2 participants