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: RFC3339Nano does not support comma-separated fractional seconds #24860

Closed
JeanMertz opened this issue Apr 14, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@JeanMertz
Copy link

commented Apr 14, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.10 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

GOARCH="amd64"
GOOS="darwin"

What did you do?

package main

import (
	"fmt"
	"time"
)

func main() {
	t, err := time.Parse(time.RFC3339Nano, "2018-04-14T15:22:24,859303000+00:00")
	if err != nil {
		panic(err)
	}
	fmt.Println(t.String())
}

What did you expect to see?

2018-04-14 15:22:24.859303 +0000 UTC

What did you see instead?

panic: parsing time "2018-04-14T15:22:24,859303000+00:00" as "2006-01-02T15:04:05.999999999Z07:00": cannot parse ",859303000+00:00" as "Z07:00"


I ran across this while I was combining a small go utility with some unix utilities. One of those utilities was GNU's date, which I used as follows:

date -u --iso-8601=ns
2018-04-14T15:36:21,837840000+00:00

I was surprised to see a comma (,) to denote the fractional seconds.

Now, interestingly enough, if I use --rfc-3339=ns, it returns a dot (.):

date -u --rfc-3339=ns
2018-04-14 15:38:42.023325000+00:00

I dug into the RFC3339 spec, and found that using a comma is perfectly valid:

Time:

   time-hour         = 2DIGIT ; 00-24
   time-minute       = 2DIGIT ; 00-59
   time-second       = 2DIGIT ; 00-58, 00-59, 00-60 based on
                              ; leap-second rules
+  time-fraction     = ("," / ".") 1*DIGIT
   time-numoffset    = ("+" / "-") time-hour [[":"] time-minute]
   time-zone         = "Z" / time-numoffset

   timeopt-hour      = "-" / (time-hour [":"])
   timeopt-minute    = "-" / (time-minute [":"])

   timespec-hour     = time-hour [[":"] time-minute [[":"] time-second]]
   timespec-minute   = timeopt-hour time-minute [[":"] time-second]
   timespec-second   = "-" timeopt-minute time-second
   timespec-base     = timespec-hour / timespec-minute / timespec-second

   time              = timespec-base [time-fraction] [time-zone]

   iso-date-time     = date "T" time

As I said, I can work around this, but I figured I create this issue to see if this is something that should be fixed in Go, or if not, and the issue is closed, anyone else running into this can at least find the issue and know what's going on 👍

@JeanMertz

This comment has been minimized.

Copy link
Author

commented Apr 14, 2018

Actually, reading through the RFC again, I think Go is correct to not support comma-separated fraction seconds. The part I copied is from the Appendix A. ISO 8601 Collected ABNF appendix, while 5.6. Internet Date/Time Format doesn't mention the comma, and in fact states:

The following profile of ISO 8601 [ISO8601] dates SHOULD be used in
new protocols on the Internet. This is specified using the syntax
description notation defined in [ABNF].

So it seems like this is working as intended, and I should watch out for using --iso8601=ns when using GNU's date.

@JeanMertz JeanMertz closed this Apr 14, 2018

@pam4

This comment has been minimized.

Copy link

commented Apr 14, 2018

@JeanMertz See also #6189

@JeanMertz

This comment has been minimized.

Copy link
Author

commented Apr 14, 2018

Thanks @pam4 I searched for existing issues, but was unable to find any. I guess I didn't use the right search parameters.

@golang golang locked and limited conversation to collaborators Apr 14, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.