-
Notifications
You must be signed in to change notification settings - Fork 156
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 values are unweildy #16
Comments
Totally agree! Can you provide a test that reproduces it? I got a much shorter output last time I tried to reproduce the behavior in a test.
|
Maybe package pretty should use TextMarshaler for types that satisfy it. That would cover time.Time. |
For example, this test: func TestTime(t *testing.T) {
type timer struct {
t time.Time
}
tt := timer{t: time.Now()}
s := fmt.Sprintf("%# v", Formatter(tt.t))
t.Log(s)
} Produces this output from formatter_test.go:271: time.Time{
sec: 63547633031,
nsec: 0xfb4f9b0,
loc: &time.Location{},
} While that's probably not ideal, I'm not able to reproduce the massive output you're getting. |
Tossed up #17 with a test but no implementation to use TextMarshaler for time.Time specifically. Was able to reproduce the larger output by printing the time before pretty printing the time. |
I took a minute to implement this today, but I think it's not possible for unexported struct fields, e.g. type t struct {
x time.Time // note x is lowercase
} |
I loved what this package gave me initially, but I ran into this problem as well. I came across it with an embedded time.Time in a struct I needed for custom UnmarshalXML. I tried to use a Stringer interface on the struct as well as a GoStringer interface before dropping into the code to see how this package constructed the output. I've only been writing go a few weeks so my knowladge of the API is still a little limited - any ideas for this issue in the last year? |
+1, It's a
|
Also hitting this. For my purposes it largely renders pretty unworkable because the output is so large whenever you have a time value in a struct. You have to wade through the reams of output for the time values to see the wood between the trees. This is a shame, because otherwise pretty does exactly what I'd want for debugging and so on. |
It seems to me the much better solution would be to special-case If I have time next week I may write up a PR for that. |
Go 1.17 will add a GoString method on Time values. https://tip.golang.org/doc/go1.17#time That might be sufficient for us to close this issue. |
It doesn't appear to have helped, at least if a |
I just printed a time field and got this out. I understand that might be the desired behaviour in some cases, but it would be nice if there was a way to specify that a given type should have a simplified pretty form - this is a bit silly.
The text was updated successfully, but these errors were encountered: