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: Time has different precision depending on the operating system #41087

Open
davidterranova opened this issue Aug 28, 2020 · 4 comments
Open

time: Time has different precision depending on the operating system #41087

davidterranova opened this issue Aug 28, 2020 · 4 comments
Milestone

Comments

@davidterranova
Copy link

@davidterranova davidterranova commented Aug 28, 2020

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

$ go version
go version go1.13.12 darwin/amd64

Does this issue reproduce with the latest release?

$ go version
go version go1.15 darwin/amd64
$ go run main.go
2020-08-28 10:37:50.388561 +0200 CEST m=+0.000120847
$ go version
go version go1.15 linux/amd64
$ go run main.go
2020-08-28 08:44:47.598714765 +0000 UTC m=+0.000071254

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/davidterranova/Library/Caches/go-build"
GOENV="/Users/davidterranova/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/davidterranova/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/opt/go/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/davidterranova/Documents/development/smallpdf/pro/go.mod"
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/j_/6_9hdtls6tb_yvmfygpy54jm0000gn/T/go-build886013447=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

package main

import (
  "time""
  "fmt"
)

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

Has different time precisions depending on the operating system it is being ran.

  • micro second precision on MacOS Catalina
  • nano second precision on linux
  • micro second on Windows

What did you expect to see?

Either the same time precision or the mention of these differences in the documentation of the package time

@davecheney
Copy link
Contributor

@davecheney davecheney commented Aug 28, 2020

What about time stamps received from file systems? The reason I ask is different file systems support different levels of precision so the fidelity of an os.FileInfo is dependant on which file system the file is referenced from.

Istm that in both the time now case and the os fileinfo case the only thing that can be documented is the precision of the time stamp value is operating system dependant.

@alexbrainman
Copy link
Member

@alexbrainman alexbrainman commented Aug 28, 2020

  • micro second on Windows

How did you measure that? Because it is about 1 millisecond, if you use time.Sleep function. I agree with @davecheney - it is too complicated to explain. And what happens, if things will change in time? The only thing we can document that it is operating system dependant. I just don't see how that will help anyone.

Alex

@davidterranova
Copy link
Author

@davidterranova davidterranova commented Aug 28, 2020

@davecheney Filesystems are IO. I don't think we can do much. Same for databases (postgreSQL does support micro second precision only).

@alexbrainman I didn't but peterGo on the mailing list mentioned it.

I think we can improve the documentation mentioning the time precision can be different depending on the os

@cagedmantis cagedmantis changed the title time.Time has different precision depending on the operating system time: time.Time has different precision depending on the operating system Aug 28, 2020
@bcmills
Copy link
Member

@bcmills bcmills commented Aug 28, 2020

I don't think it is the precision of time.Time itself that actually varies. Rather, it is the precision of time.Now(). (To my knowledge, timestamps computed with time.UnixNano and (time.Time).Add have the same precision on all platforms.)

@dmitshur dmitshur added this to the Backlog milestone Aug 31, 2020
@dmitshur dmitshur changed the title time: time.Time has different precision depending on the operating system time: Time has different precision depending on the operating system Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.