-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
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:00I 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" timeAs 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 👍