2019-02-13 21:55:13 -05:00
|
|
|
package chart
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Assert types implement interfaces.
|
|
|
|
var (
|
2022-01-10 18:52:32 -05:00
|
|
|
_ Sequence[float64] = (*Times)(nil)
|
|
|
|
_ sort.Interface = (*Times)(nil)
|
2019-02-13 21:55:13 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// Times are an array of times.
|
|
|
|
// It wraps the array with methods that implement `seq.Provider`.
|
|
|
|
type Times []time.Time
|
|
|
|
|
|
|
|
// Array returns the times to an array.
|
|
|
|
func (t Times) Array() []time.Time {
|
|
|
|
return []time.Time(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Len returns the length of the array.
|
|
|
|
func (t Times) Len() int {
|
|
|
|
return len(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetValue returns a value at an index as a time.
|
|
|
|
func (t Times) GetValue(index int) float64 {
|
2019-04-24 16:00:09 -04:00
|
|
|
return ToFloat64(t[index])
|
2019-02-13 21:55:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Swap implements sort.Interface.
|
|
|
|
func (t Times) Swap(i, j int) {
|
|
|
|
t[i], t[j] = t[j], t[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Less implements sort.Interface.
|
|
|
|
func (t Times) Less(i, j int) bool {
|
|
|
|
return t[i].Before(t[j])
|
|
|
|
}
|
2019-04-24 16:00:09 -04:00
|
|
|
|
|
|
|
// ToFloat64 returns a float64 representation of a time.
|
|
|
|
func ToFloat64(t time.Time) float64 {
|
|
|
|
return float64(t.UnixNano())
|
|
|
|
}
|