-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -451,41 +451,70 @@ func (ts ConstantTicks) Ticks(float64, float64) []Tick { | |
| return ts | ||
| } | ||
|
|
||
| // UnixTimeTicks is suitable for axes representing time values. | ||
| // 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. | ||
| type TimeTicks 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 | ||
|
|
||
| // Converter takes a float64 value and converts it into a time.Time. | ||
| // If nil, UnixTimeConverter will be used. | ||
| Converter TimeFloatConverter | ||
| } | ||
|
|
||
| var _ Ticker = UnixTimeTicks{} | ||
| var _ Ticker = TimeTicks{} | ||
|
|
||
| // Ticks implements plot.Ticker. | ||
| func (utt UnixTimeTicks) Ticks(min, max float64) []Tick { | ||
| if utt.Ticker == nil { | ||
| utt.Ticker = DefaultTicks{} | ||
| func (tt TimeTicks) Ticks(min, max float64) []Tick { | ||
| if tt.Ticker == nil { | ||
| tt.Ticker = DefaultTicks{} | ||
| } | ||
| if tt.Format == "" { | ||
| tt.Format = time.RFC3339 | ||
| } | ||
| if utt.Format == "" { | ||
| utt.Format = time.RFC3339 | ||
| if tt.Converter == nil { | ||
| tt.Converter = UnixTimeConverter{} | ||
| } | ||
|
|
||
| ticks := utt.Ticker.Ticks(min, max) | ||
| ticks := tt.Ticker.Ticks(min, max) | ||
| for i := range ticks { | ||
| tick := &ticks[i] | ||
| if tick.Label == "" { | ||
| continue | ||
| } | ||
| t := time.Unix(int64(tick.Value), 0) | ||
| tick.Label = t.Format(utt.Format) | ||
| t := tt.Converter.UnmarshalTime(tick.Value) | ||
| tick.Label = t.Format(tt.Format) | ||
| } | ||
| return ticks | ||
| } | ||
|
|
||
| // TimeFloatConverter converts back and forth a time.Time value into | ||
| // a float64. | ||
| type TimeFloatConverter interface { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using interface I would use and have |
||
| MarshalTime(t time.Time) float64 | ||
| UnmarshalTime(float64) time.Time | ||
| } | ||
|
|
||
| // UnixTimeConverter converts a time.Time value into the float64 representation | ||
| // of Unix time, using the UTC time location. | ||
| type UnixTimeConverter struct{} | ||
|
|
||
| // MarshalTime implements TimeFloatConverter. | ||
| func (UnixTimeConverter) MarshalTime(t time.Time) float64 { | ||
| v := t.UTC().Unix() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. calling UTC() here is not necessary
|
||
| return float64(v) | ||
| } | ||
|
|
||
| // UnmarshalTime implements TimeFloatConverter. | ||
| func (UnixTimeConverter) UnmarshalTime(v float64) time.Time { | ||
| return time.Unix(int64(v), 0).UTC() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using UTC as default here is fine, but it would be good to make it configurable. |
||
| } | ||
|
|
||
| // A Tick is a single tick mark on an axis. | ||
| type Tick struct { | ||
| // Value is the data value marked by this Tick. | ||
|
|
||
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.