Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time: no Parse format for GNU style RFC3339 #25937

Closed
stub42 opened this issue Jun 18, 2018 · 5 comments
Closed

time: no Parse format for GNU style RFC3339 #25937

stub42 opened this issue Jun 18, 2018 · 5 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@stub42
Copy link

stub42 commented Jun 18, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.10.3 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

Ubuntu 18.04, amd64

What did you do?

Attempted to time.Parse the result of 'date --utc --rfc-3339=ns':

time.Parse(time.RFC3339Nano, "2018-06-18 10:19:31.800140702+00:00")
package main

import (
	"fmt"
	"os/exec"
	"strings"
	"time"
)

func main() {
	raw, err := exec.Command("date", "--utc", "--rfc-3339=ns").Output()
	if err != nil {
		panic(fmt.Sprintf("failed to run date: %v", err))
	}
	from_ubuntu := strings.TrimSpace(string(raw))
	t, err := time.Parse(time.RFC3339Nano, from_ubuntu)
	if err != nil {
		fmt.Printf("Unparsable: %q\n", string(from_ubuntu))
	} else {
		fmt.Printf("Parsed: %v\n", t)
	}
}

What did you expect to see?

Parsing to succeed

What did you see instead?

Failure, due to an old disagreement about the RFC: http://lists.gnu.org/archive/html/bug-coreutils/2006-05/msg00019.html

GNU coreutils team maintain whitespace is allowed, but the Go library requires the 'T' separator between the date and time components of the string representation.

Options to allow interoperability between GNU style and Go style RFC-3339 complient strings would be to either relax the Go parsing, or provide alternative predefined styles in the time package (time.RFC3339GNU and time.RFC3339NanoGNU, or time.GNU3339 and time.GNU3339Nano, or similar)

@josharian josharian changed the title No time.Parse format for GNU style RFC3339 time: no Parse format for GNU style RFC3339 Jun 18, 2018
@agnivade
Copy link
Contributor

/cc @rsc

@agnivade agnivade added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Jun 18, 2018
@agnivade agnivade added this to the Unplanned milestone Jun 18, 2018
@ulikunitz
Copy link
Contributor

While there is a note in RFC3339 saying that applications may choose to replace the T with a space, this is not what the formal ABNF specification there supports. The underlying ISO 8601 standards mandates the use of the T. Since any application choosing to support space can easily define their own constants, I don't think new constants in time are needed.

@ianlancetaylor
Copy link
Contributor

I don't see a need to change anything here. We appear to follow the RFC. It's easy to adapt.

@crawford
Copy link

Taken directly from the RFC:

NOTE: ISO 8601 defines date and time separated by "T".
Applications using this syntax may choose, for the sake of
readability, to specify a full-date and full-time separated by
(say) a space character.

Yes, the ABNF doesn't included characters other than T, but there is a second note which makes it clear that the ABNF is not exhaustive:

NOTE: Per [ABNF] and ISO8601, the "T" and "Z" characters in this
syntax may alternatively be lower case "t" or "z" respectively.

As such, I would argue that the time library doesn't fully conform to RFC3339.

@ianlancetaylor
Copy link
Contributor

@crawford This issue is closed, and we don't track comments on closed issues. You can write formats yourself to do whatever you need.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

6 participants