-
Notifications
You must be signed in to change notification settings - Fork 204
plotter: use a fixed time zone for tests #278
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
Conversation
|
It's been 132 years. I think it's time to let go ;P This does not fix the problem; UTC is just as fixed as Paris time. I think the issue is interplay with the locale that is used by formatting and the locale that is used during parsing, though I can't find a combinations of locales that fixes it. |
|
You need to use the local timezone to create the original time values. The timezone is lost when you convert to unix seconds |
|
I tried that when I reported the issue and it doesn't work: There is another failure there, which I have not yet investigated. |
|
Are those two separate thoughts: 1. that you tried it, and 2. that you Anyway, I'm still confused. How can it fail if you use local time? If you On Fri, Apr 22, 2016 at 6:56 AM Dan Kortschak notifications@github.com
|
|
so... the fix would actually be to modify: to return a t := time.Unix(int64(tick.Value), 0).UTC()then, perhaps the right fix would be to add another field to type UnixTimeTicks struct {
// Ticker is used to generate a set of ticks.
// If nil, DefaultTicks will be used.
Ticker Ticker
// Format is the textual representation of the time value.
// If empty, time.RFC3339 will be used
Format string
// Convert takes a float64 value and converts it into a time.Time.
// If nil, time.Unix will be used.
Convert func(float64) time.Time
} |
|
They are separate things. I didn't look into the second failure because the test golden image mutation gets in the way of debugging the issue.
|
|
@sbinet, another option is instead of having Convert, have the user specify a timezone in the ticker, defaulting to Local. However, I still want to know why using Local all of the way through doesn't work. |
|
I have looked into this issue and found the following:
I hope this helps. As far as the code change is concerned I would prefer to have UnixTimeTicks.Location field instead of UnixTimeTicks.Convert function (as suggested by @eaburns). |
|
With Go 1.6.2 all tests pass (apart from timestamp test as I am in UTC+8). I suspect that Go 1.7 produces different images comparing to Go 1.6 due to compression algorithms changes in |
|
@kostya-sh thanks for giving it a try (and raising the issue wrt wrt having a Just for my own information, did my alternate PR (the #278 one with |
|
? Your PR with UTC fixes the problem, but if you use Local() both to create timestamps and to convert them then the test fails because the golden file has been created using different data. To fix it you can either:
|
This sounds good to me. |
This CL introduces the TimeFloatConverter interface that describes how a time.Time value is converted to a float64 (and back.) A default TimeFloatConverter (used by TimeTicks) is also provided in the shape of UnixTimeConverter. Test updated to be resilient against timezones (tested with 'Europe/Paris', 'America/Los_Angeles' and 'Australia/Sydney') Fixes gonum#278.
8081980 to
fd4b9e8
Compare
This CL introduces the TimeFloatConverter interface that describes how a time.Time value is converted to a float64 (and back.) A default TimeFloatConverter (used by TimeTicks) is also provided in the shape of UnixTimeConverter. Test updated to be resilient against timezones (tested with 'Europe/Paris', 'America/Los_Angeles' and 'Australia/Sydney') Fixes gonum#278.
|
PTAL. |
|
interestingly, my first approach of (un)marshaling too bad. |
|
@sbinet I think converting from time.Time to float64 (
Secondly it is not possible to customize Location that is used to format dates. Currenly it is hardcoded to UTC. See also some comments inline. |
| // UnixTimeTicks expects values in Unix time seconds. | ||
| type UnixTimeTicks struct { | ||
| // TimeTicks is suitable for axes representing time values. | ||
| // By default, TimeTicks expects values in (UTC) Unix time seconds. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unix time represents moment in time. It is time zone independent, so (UTC) Unix time seconds doesn't make sense.
|
I left a few comments however despite being the one who proposed the idea of having more flexible TimeTicks type I really like the simplicity of the original UnixTimeTicks type and still think that adding Location field to it was all that required ;) |
|
@kostya-sh , yes, it is somewhat a bit less compact to write. I could introduce: func UnixTimeTicks(format string, cnv TimeFloatConverter) TimeTicks {
if format == "" {
format = time.RFC3339
}
if cnv == nil {
cnv = UnixTimeConverter{}
}
return TimeTicks{
Format: format,
Converter: cnv,
}
}to have a more direct way to have a properly configured |
This CL introduces the TimeFloatConverter interface that describes how a time.Time value is converted to a float64 (and back.) A default TimeFloatConverter (used by TimeTicks) is also provided in the shape of UnixTimeConverter. Test updated to be resilient against timezones (tested with 'Europe/Paris', 'America/Los_Angeles' and 'Australia/Sydney') Fixes gonum#276.
|
I had another look at ticker related functionality in plot package and I think it might be good idea to split Ticker interface into two: Ticker and Labeler. This will allow to specify ticker rules and formatting rules independently. For example LogTicks and DefaultTicks and ConstantTicks use the same formatting rules but different ticker rules. UnixTimeTicks and DefaultTicks have the same ticker rules but different formatting rules. Also if ConstantTicks is just a []float64 it is much easier to create in code. It might be good idea in addition to the time specific formatter provide time specific ticker as well (that can prefer ticks at the beginning of major time intervals such as minutes or months depending on range). Having a seprate Labeler interface will also make it easy to provide FloatLabeler with configurable precision if necessary. Thoughts? Should I bring this question on the mainling list instead? |
|
SGTM. |
|
Ok, I will send a PR for review soon. |
|
See #286 |
|
Can we merge this in the interim. Having a failing case here is hampering what I can do. |
|
ping |
|
@sbinet Is there a particular hold up here that I can help with? |
|
I'm going to close this. If it is going to be revived, please reopen. |
|
I don't understand that logic. It certainly will not get reviewed if it's closed. Are you waiting for me or someone in particular to review? |
|
It's stale and hasn't moved for months. If I get some time I will try to put together a good.
|
Fixes #276