Skip to content

time: output does not respect comma as millisecond separator #48037

Closed
@746B61

Description

@746B61

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

$ go version
go version go1.17 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/xxx/.cache/go-build"
GOENV="/home/xxx/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/xxx/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/xxx/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17"
GCCGO="gccgo"
AR="ar"
CC="x86_64-pc-linux-gnu-gcc"
CXX="x86_64-pc-linux-gnu-g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1250957969=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I used time.Format to format a time including milliseconds with layout string "15:04:05,000". Before go 1.17, the comma was not recognized as separator for milliseconds and the string ,000 was added to the format output verbatim. The result was for example 23:00:12,000. Since go 1.17, the comma is recognized as separator for milliseconds, but changed to a period in the output. The result now is for example 23:00:12.345. I expect the result respect the comma in the layout string and getting 23:00:12,345.

Having the zeros replaced with the actual milliseconds changed the behavior to previous versions but is an improvement from my perspective. But, the changed behavior regarding the comma as separator breaks existing code that relies on a comma being used, e.g., because it is parsed by some other system later on.

Example code: https://play.golang.org/p/Bq6p4dxqhgG

What did you expect to see?

23:00:12,345
(or 23:00:12,000 as in go <1.17)

What did you see instead?

23:00:12.345

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions