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: time.String() defines format only in comment, with no matching Parse string #9596

Closed
mattyw opened this issue Jan 15, 2015 · 8 comments

Comments

Projects
None yet
7 participants
@mattyw
Copy link
Contributor

commented Jan 15, 2015

The documentation for time.String() shows the format used to convert time into a string: http://golang.org/pkg/time/#Time.String.

This string appears to be different to the const formats already defined in the time package, so if I wanted to naively (not using time.Format) convert a time -> string -> time I'd need to copy the format from the docs into my code and use it in a call to time.Parse.

In addition this format string is used a few times in http://golang.org/src/time/format_test.go as a literal string.

Isn't this format string a good candidate to be placed in the consts?

@ianlancetaylor ianlancetaylor changed the title time.String() defines format in comment time: time.String() defines format only in comment, with no matching Parse string Jan 15, 2015

@rogpeppe

This comment has been minimized.

Copy link
Contributor

commented Jan 15, 2015

+1
I've considered raising this an an issue before.
Too late now, but I wish time.String() produced RFC3339,
the same format used by default in the marshaling methods.

@martisch

This comment has been minimized.

Copy link
Member

commented Jan 15, 2015

https://github.com/golang/go/blob/master/src/time/format.go#L400

We cant change it currently but we could use a const here and add it to the format consts that are exported. That would not change the output and give others access to the format string. If later a incompatible change is possible we can define that new const as RFC3339.

What would be a good name for it? StdDate?

@rogpeppe

This comment has been minimized.

Copy link
Contributor

commented Jan 15, 2015

I suggested TimeString as a possibility. I did consider Std, but it's not really "standard".

@martisch

This comment has been minimized.

Copy link
Member

commented Jan 15, 2015

Since it is already in the time package. time.FormatString sounds better to me.

@nightlyone

This comment has been minimized.

Copy link
Contributor

commented Jan 15, 2015

What about "time.Go" since we have already "time.Ruby" and this would resonate.

@martisch

This comment has been minimized.

Copy link
Member

commented Jan 15, 2015

We have "time.RubyDate" so then it would rather be "time.GoDate" however this sounds to me more like its special and not so much the default for String().

@dominikh

This comment has been minimized.

Copy link
Member

commented Jan 15, 2015

This is a duplicate of issue #6587

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jan 15, 2015

So it is, and that issue was closed as working as intended. So, closing.

@golang golang locked and limited conversation to collaborators Jun 25, 2016

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.