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: Parse does not parse format "1504059999" #23134

Closed
tehsphinx opened this issue Dec 14, 2017 · 7 comments
Closed

time: Parse does not parse format "1504059999" #23134

tehsphinx opened this issue Dec 14, 2017 · 7 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@tehsphinx
Copy link

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

go version go1.9.2 darwin/amd64

Does this issue reproduce with the latest release?

go 1.9.2 is currently the latest release

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

darwin/amd64

What did you do?

I try to parse a time format without any punctuation. Date is not of importance here.

time.Parse("1504059999", "0244541440")

https://play.golang.org/p/-YxQX44J8F

What did you expect to see?

0000-01-01 02:44:54.144 +0000 UTC

What did you see instead?

parsing time "0244541440" as "1504059999": cannot parse "1440" as "9999"
@mvdan mvdan changed the title time.Parse does not parse format "1504059999" time: Parse does not parse format "1504059999" Dec 14, 2017
@mvdan
Copy link
Member

mvdan commented Dec 14, 2017

I could not find a good reason in your code nor in the time package godoc, so I digged into the code a bit.

In particular, after some debugging, I came to this comment:

case '.': // .000 or .999 - repeated digits for fractional seconds.

In other words, any number of 9 digits to signal fractional seconds are only valid format if they follow a period.

Without knowing too much about how the time package works or what's the design behind these layouts, it seems to me like this restriction could be avoided. I'll play with it for a bit to see what I get. Would like some input from @rsc as per https://golang.org/s/owners.

@mvdan
Copy link
Member

mvdan commented Dec 14, 2017

To clarify - 000 cannot be used in place of .000 easily, as it introduces certain ambiguity with others like 01 or 02. However, 999 doesn't seem to have that problem.

@ianlancetaylor
Copy link
Contributor

Since you know the exact layout, it's easy enough to modify the input string to have the dot that the format requires. I'm not sure this is worth changing.

@tehsphinx
Copy link
Author

I'm already working around it by modifying the input string and adding a ..

I was just wondering that there is a . required and could not find or think of any good reason for it. Modifying the string gives me additional points of failure, e.g. if the string is not the format or length I was expecting.

Of course I can give it a try if you'd like a PR. Never done that for the go standard library though.

@mvdan mvdan added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Dec 15, 2017
@mvdan
Copy link
Member

mvdan commented Dec 15, 2017

I would say we first need to decide if we want this change or not. That is, to allow 9999 as well as .9999. The change itself isn't complicated - I have a working version stashed on my laptop.

@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone Dec 15, 2017
@rsc
Copy link
Contributor

rsc commented Jan 29, 2018

A decimal point followed by one or more zeros represents a fractional
second, printed to the given number of decimal places. A decimal point
followed by one or more nines represents a fractional second, printed to the
given number of decimal places, with trailing zeros removed. When parsing
(only), the input may contain a fractional second field immediately after
the seconds field, even if the layout does not signify its presence. In that
case a decimal point followed by a maximal series of digits is parsed as a
fractional second.

There is no decimal point here. This is probably working best as is.

@rsc rsc closed this as completed Jan 29, 2018
@tehsphinx
Copy link
Author

Just to throw in another argument:
The German language for example would not use a . but a , for separating fractional seconds. That case is also not covered by the current implementation.

@golang golang locked and limited conversation to collaborators Jan 31, 2019
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

5 participants