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

@mattyw
Copy link
Contributor

mattyw 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
Copy link
Contributor

+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
Copy link
Contributor

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
Copy link
Contributor

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

@martisch
Copy link
Contributor

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

@nightlyone
Copy link
Contributor

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

@martisch
Copy link
Contributor

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

This is a duplicate of issue #6587

@ianlancetaylor
Copy link
Contributor

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.
Projects
None yet
Development

No branches or pull requests

7 participants