You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Background: saving to database and generating the result giving different diff because of timezone difference
minimal code to reproduce:
package foo
import"time"import"github.com/hexops/autogold"import"testing"funcTestFoo(t*testing.T) {
constlayout="Jan 2, 2006 at 3:04pm (MST)"tm, _:=time.Parse(layout, "Feb 4, 2014 at 6:05pm (PST)")
t2:=tm.UTC() // assuming this result queried from database from column that doesn't store timezoneprintln(tm.UnixNano(), t2.UnixNano(), tm.UnixNano() ==t2.UnixNano()) // both are inherently equalwant:=autogold.Want("internally equal", t2)
want.Equal(t, tm)
}
it shows:
1391537100000000000 1391537100000000000 true
--- FAIL: TestFoo (0.06s)
want.go:200: mismatch (-want +got):
--- want
+++ got
@@ -1 +1,10 @@
-time.Time{ext: 63527133900}
\ No newline at end of file
+time.Time{ext: 63527133900, loc: &time.Location{
+ name: "PST",
+ zone: []time.zone{time.zone{
+ name: "PST",
+ }},
+ tx: []time.zoneTrans{time.zoneTrans{when: -9223372036854775808}},
+ cacheStart: -9223372036854775808,
+ cacheEnd: 9223372036854775807,
+ cacheZone: &time.zone{name: "PST"},
+}}
\ No newline at end of file
FAIL
FAIL command-line-arguments 0.060s
FAIL
where it inherently the same.
Is there a way to customize the generated struct to be using time.Unix(sec, nanosec) instead of full struct since &time.Time{ext:123} has unexported field?
Is there a way to customize the comparison of value so it would consider inherently equal time ignoring the timezone as equal?
The text was updated successfully, but these errors were encountered:
In practice, though, I suggest that when your data structures become this complex you bail out of the default formatting and instead create a simpler struct (or string) just for passing to valast.
slimsag
changed the title
Feature Request: custom time.Time/datatype result generation and comparison
valast: feature Request: custom time.Time/datatype result generation and comparison
Dec 20, 2022
Background: saving to database and generating the result giving different diff because of timezone difference
minimal code to reproduce:
it shows:
where it inherently the same.
time.Unix(sec, nanosec)
instead of full struct since&time.Time{ext:123}
has unexported field?The text was updated successfully, but these errors were encountered: