Skip to content

proposal: time: add method to compare Location values #31686

@rsned

Description

@rsned

What did you do?

I was trying to write some unit tests that my code returned the right *time.Location, but all my attempts to compare the results failed.

https://play.golang.org/p/xQpqTvYQezo

What did you expect to see?

Requesting the same location should have produced two values that would be equal.

x==y seems to just use the pointers, so it's not a deep equal.

Given the private fields in Location, there should be a method on Location that compares the name and the offset to see if they are really equal.

What did you see instead?

Values were not equivalent.

Does this issue reproduce with the latest release (go1.12.4)?

yes

System details

go version go1.12 linux/amd64
GOARCH="amd64"
GOBIN="/usr/lib/google-golang/bin"
GOCACHE="/usr/local/google/home/roberts/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/usr/lib/google-golang/bin/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/google-golang"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/google-golang/pkg/tool/linux_amd64"
GCCGO="/usr/bin/gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
GOROOT/bin/go version: go version go1.12 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.12
uname -sr: Linux 4.18.10-1rodete2-amd64
Distributor ID:	Debian
Description:	Debian GNU/Linux rodete (upgraded from: Ubuntu 14.04.5 LTS)
Release:	rodete
Codename:	rodete
/lib/x86_64-linux-gnu/libc.so.6: GNU C Library (Debian GLIBC 2.24-12) stable release version 2.24, by Roland McGrath et al.
gdb --version: GNU gdb (GDB) 8.2-gg10

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions