Skip to content

time: (Time).Zone() returns empty timezone string "" on Darwin and "UTC" on Linux after UnmarshalText("9066-03-06T6:05:06Z") or using any valid year #45909

@odeke-em

Description

@odeke-em

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

Go1.17, Go1.16, Go1.15 the rest I haven't tested

Does this issue reproduce with the latest release?

Yes!

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

Alternating between Darwin and Linux

What did you do?

Looking a bug reported from oss-fuzz that just came from a reflection check failure when the location of a time parsed from
"9066-03-06T6:05:06-00:00" via UnmarshalText and round trip MarshalText then UnmarshalText again per https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=33092&q=label%3AProj-golang

while digging more, I ran https://play.golang.org/p/ealMZGPl7NX or inlined below

package main

import (
	"fmt"
	"runtime"
	"time"
)

func main() {
	var t1 time.Time
	b1 := []byte("9066-03-06T6:05:06Z")
	if err := t1.UnmarshalText(b1); err != nil {
		panic(err)
	}
	println(runtime.Version(), runtime.GOOS)
	var t2 time.Time
	b2, err := t1.MarshalText()
	if err != nil {
		panic(err)
	}
	if err := t2.UnmarshalText(b2); err != nil {
		panic(err)
	}
	z1, o1 := t1.Zone()
	z2, o2 := t2.Zone()
	fmt.Printf("t1:: %#v\nt2:: %#v\nb1:: %q\nb2:: %q\n", t1, t2, b1, b2)
	fmt.Printf("t1:: zone: %q offset: %d\n", z1, o1)
	fmt.Printf("t2:: zone: %q offset: %d\n", z2, o2)
}

What did you expect to see?

On both Linux and Darwin, I expected to see at the end

t1:: zone: "UTC" offset: 0
t2:: zone: "UTC" offset: 0

What did you see instead?

On Linux, I correctly at the end see

t1:: zone: "UTC" offset: 0
t2:: zone: "UTC" offset: 0

on Darwin, I see only

t1:: zone: "" offset: 0
t2:: zone: "UTC" offset: 0

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.WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions