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/format: Error parsing time format with European offset #43813

Closed
haskovec opened this issue Jan 20, 2021 · 2 comments
Closed

time/format: Error parsing time format with European offset #43813

haskovec opened this issue Jan 20, 2021 · 2 comments

Comments

@haskovec
Copy link

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

$ go version

go version go1.15.6 darwin/amd64

Does this issue reproduce with the latest release?

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

go env Output
$ go env

What did you do?

When I try to parse a time returned by a workfront instance with a European time offset Go fails to parse it. The time format returned is 2020-08-17T17:00:00:000+0100

To reproduce I wrote the following test code:

func TestWorkfrontDateFormat(t *testing.T) {
	workfrontDate := "2020-08-17T17:00:00:000+0100"  //Set for European timezone

	_, err := time.Parse("2006-01-02T15:04:50:000-0700", workfrontDate)
	if err != nil {
		t.Errorf("Error parsing European Date: %#v", err)
	}
}

What did you expect to see?

I would expect it to correctly parse the time.

What did you see instead?

It returns an error object:

&time.ParseError{Layout:"2006-01-02T15:04:50:000-0700", Value:"2020-08-17T17:00:00:000+0100", LayoutElem:"0:000", ValueElem:":000+0100", Message:""}
@seankhliao
Copy link
Member

closed as dup of #36145 , please comment/reopen if you disagree

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/300996 mentions this issue: time: support "," as separator for fractional seconds

gopherbot pushed a commit that referenced this issue Mar 16, 2021
Accepts comma "," as a separator for fractional seconds
hence we now accept:
* 2006-01-02 15:04:05,999999999 -0700 MST
* Mon Jan _2 15:04:05,120007 2006
* Mon Jan 2 15:04:05,120007 2006

This change follows the recommendations of ISO 8601 per

   https://en.wikipedia.org/wiki/ISO_8601#cite_note-26

which states

   ISO 8601:2004(E), ISO, 2004-12-01, "4.2.2.4 ...
   the decimal fraction shall be divided from the integer
   part by the decimal sign specified in ISO 31-0, i.e.
   the comma [,] or full stop [.]. Of these, the comma
   is the preferred sign."

Unfortunately, I couldn't directly access the ISO 8601 document
because suddenly it is behind a paywall on the ISO website,
charging CHF 158 (USD 179) for 38 pages :-(

However, this follows publicly available cited literature, as well
as the recommendations from the proposal approval.

Fixes #6189
Updates #27746
Updates #26002
Updates #36145
Updates #43813
Fixes #43823

Change-Id: Ibe96064e8ee27c239be78c880fa561a1a41e190c
Reviewed-on: https://go-review.googlesource.com/c/go/+/300996
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Rob Pike <r@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Mar 12, 2022
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

3 participants