]> Cypherpunks repositories - gostls13.git/commitdiff
time: add comment explaining rejection of years outside [0000,9999]
authorRuss Cox <rsc@golang.org>
Tue, 25 Mar 2014 00:34:17 +0000 (20:34 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 25 Mar 2014 00:34:17 +0000 (20:34 -0400)
This has come up twice now. Redirect future questions
to the explanation in the issue tracker.

LGTM=iant, r
R=r, iant
CC=golang-codereviews
https://golang.org/cl/79550043

src/pkg/time/time.go

index c504df74013a88678d47279b5823fd49e8a8f2a2..0a2b0914283e8f85622934976944fb843c1c509f 100644 (file)
@@ -934,6 +934,8 @@ func (t *Time) GobDecode(data []byte) error {
 // The time is a quoted string in RFC 3339 format, with sub-second precision added if present.
 func (t Time) MarshalJSON() ([]byte, error) {
        if y := t.Year(); y < 0 || y >= 10000 {
+               // RFC 3339 is clear that years are 4 digits exactly.
+               // See golang.org/issue/4556#c15 for more discussion.
                return nil, errors.New("Time.MarshalJSON: year outside of range [0,9999]")
        }
        return []byte(t.Format(`"` + RFC3339Nano + `"`)), nil