Skip to content

time: MarshalJSON() throws error on negative years #7566

@gopherbot

Description

@gopherbot

by verdverm:

go version devel +2bce43d48503 Mon Mar 17 12:07:30 2014 -0700 linux/amd64



What steps reproduce the problem?

try to MarshalJSON a negative date (i.e. negative year)
http://play.golang.org/p/wwfjigrteu



What happened?
Time.MarshalJSON throws an error from a check on the year range [0-9999]

It is if statement in MarshalJSON that produces the error
https://code.google.com/p/go/source/browse/src/pkg/time/time.go#936

This seems artificial, since I remember reading somewhere (which I can't find now...),
that Go's date can go back as far as 4000 something BC



What should have happened instead?

A negative date should be produced, in accordance with RFC-3339.
The play link shows that the RFC3339 format produces the correct output.
I think just the check needs to be modified or removed.

This is the same for MarshalText.
https://code.google.com/p/go/source/browse/src/pkg/time/time.go#953



Please provide any additional information below.

I figure it's about time, pardon the unintentional pun, that I give back to the Go
community. So I'd like to fix the issue as well, if that's ok with you all.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions