Skip to content

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

@iamnande

Description

@iamnande

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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions