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 · 4 comments
Closed

Comments

@JeanMertz
Copy link

JeanMertz 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
Copy link
Author

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.

@pam4
Copy link

pam4 commented Apr 14, 2018

@JeanMertz See also #6189

@JeanMertz
Copy link
Author

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
@dsnet
Copy link
Member

dsnet commented Aug 21, 2022

The quoted section of RFC 3339 is from Appendix A where the RFC tries to explain what ISO 8601 is.

The grammar for RFC 3339 is defined in section 5.6, and it is defined as a "profile of ISO 8601", which I interpret as being a particular sub-set of the ISO 8601 grammar. In particular, it does not allow for commas.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants