Skip to content

time: time#Format using time.RFC3339 using time.Time with time.Location Europe/London should use +00:00 instead of Z #68164

Closed as not planned
@jufemaiz

Description

@jufemaiz

Go version

go version go1.22.4 darwin/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN='/path/to/repo/directory/.hermit/go/bin'
GOCACHE='/Users/USERNAME/Library/Caches/go-build'
GOENV='/Users/USERNAME/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/USERNAME/go/pkg/mod'
GONOPROXY='github.com/USERNAME'
GONOSUMDB='github.com/USERNAME'
GOOS='darwin'
GOPATH='/Users/USERNAME/go'
GOPRIVATE='github.com/enosi'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/USERNAME/Library/Caches/hermit/pkg/[email protected]'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/Users/USERNAME/Library/Caches/hermit/pkg/[email protected]/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.22.4'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/path/to/repo/directory/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/9q/v1dfygx14czghp71cfmb68r00000gn/T/go-build1533160705=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Ref: https://go.dev/play/p/QLy4ID0CwiU

// You can edit this code!
// Click here and start typing.
package main

import (
	"fmt"
	"time"
)

func main() {
	tz, err := time.LoadLocation("Europe/London")
	if err != nil {
		panic(err)
	}

	tsDST := time.Date(2024, 6, 1, 0, 0, 0, 0, tz)
	tsST := time.Date(2024, 12, 1, 0, 0, 0, 0, tz)

	fmt.Println(tsDST.Format(time.RFC3339))
	fmt.Println(tsST.Format(time.RFC3339))
}

What did you see happen?

2024-06-01T00:00:00+01:00
2024-12-01T00:00:00Z

This is due to the following portion of code:

if offset == 0 {
return append(b, 'Z')
}

Now this is understandable for timezone like time.UTC, however as seen above, we've loaded a timezone that has variable.

What did you expect to see?

It would be great to see the following output for consistency:

2024-06-01T00:00:00+01:00
2024-12-01T00:00:00+00:00

However that may have breaking changes in the codebase.

An alternative would be to explicitly document time.RFC3339 to indicate that any timezone where the offset for a particular time is zero will be returned as Z not as +00:00 regardless of how the timezone may treat other points in time.

In effect, in the absence of being able to resolve a principle of least surprise issue, it would be useful to document the early exit of the time#appendFormatRFC3339 method with a Z instead of an [+-]HH:MM offset where the offset value is 0.

Alternatively, a breaking change would be to validate if the time's location is time.UTC, and use Z, otherwise use +00:00.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions