Skip to content

valast: feature Request: custom time.Time/datatype result generation and comparison #27

@kokizzu

Description

@kokizzu

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"
func TestFoo(t *testing.T) {
        const layout = "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 timezone

        println(tm.UnixNano(), t2.UnixNano(), tm.UnixNano() == t2.UnixNano()) // both are inherently equal
       
        want := 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.

  1. 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?
  2. Is there a way to customize the comparison of value so it would consider inherently equal time ignoring the timezone as equal?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions