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

time: different time.Now().UTC() values between OS flavors #37458

Closed
iamnande opened this issue Feb 25, 2020 · 1 comment
Closed

time: different time.Now().UTC() values between OS flavors #37458

iamnande opened this issue Feb 25, 2020 · 1 comment

Comments

@iamnande
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.13.8 darwin/amd64

Does this issue reproduce with the latest release?

Just saw the 1.14 release on twitter land, I shall try this shortly

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/iamnande/Library/Caches/go-build"
GOENV="/Users/iamnande/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/iamnande/src/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13.8"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13.8/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/jd/4psb1_w93tsck8n25hnjl7k40000gn/T/go-build103114280=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

given the following code in time.go:

package main

import (
	"fmt"
	"time"
)

func main() {
	fmt.Println(time.Now().UTC())
}

and the following Dockerfile:

FROM golang:1.13.8-alpine

WORKDIR /go/src/app
COPY . .

RUN go get -d -v ./...
RUN go install -v ./...

CMD ["app"]

you can run the following steps (within the workdir):

  1. go run time.go
  2. docker build -t time-test . && docker run -it --rm --name time-test time-test

and you will yield two different results; same time, however different levels of specificity.

  1. go run time.go yields: 2020-02-25 23:09:23.59933 +0000 UTC (darwin)
  2. docker time.go yields: 2020-02-25 23:09:50.499543766 +0000 UTC (alpine)

What did you expect to see?

I would expect to see the same level of accuracy within both implementations however...

What did you see instead?

I get microsecond accuracy on darwin vs nanosecond accuracy on alpine.

I did find this stackoverflow Q&A on the topic of accuracy in my searches: https://stackoverflow.com/questions/14610459/how-precise-is-gos-time-really

This is really more of a question of how I should be handling validating timestamps. Right now we're using the testify/assert package but I suppose we could deserialize and use [t.Equal()] for true timestamp validation (https://golang.org/pkg/time/#Time.Equal).

@ianlancetaylor
Copy link
Contributor

Darwin and Alpine are entirely different operating systems with entirely different kernels. There is no particular reason to think that they will provide the same timestamp precision. Go is just providing the best information that it has, so this difference doesn't really have anything to do with Go.

I'm not sure what you mean by "validating timestamps." You will get a better answer for that kind of question on a forum; see https://golang.org/wiki/Questions.

@golang golang locked and limited conversation to collaborators Feb 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants