Debian Codegraph @

times.go

raw symbols SCIP
1 package chart
2
3 import (
4 "sort"
5 "time"
6 )
7
8 // Assert types implement interfaces.
9 var (
10 _ Sequence = (*Times)(nil)
11 _ sort.Interface = (*Times)(nil)
12 )
13
14 // Times are an array of times.
15 // It wraps the array with methods that implement `seq.Provider`.
16 type Times []time.Time
17
18 // Array returns the times to an array.
19 func (t Times) Array() []time.Time {
20 return []time.Time(t)
21 }
22
23 // Len returns the length of the array.
24 func (t Times) Len() int {
25 return len(t)
26 }
27
28 // GetValue returns a value at an index as a time.
29 func (t Times) GetValue(index int) float64 {
30 return ToFloat64(t[index])
31 }
32
33 // Swap implements sort.Interface.
34 func (t Times) Swap(i, j int) {
35 t[i], t[j] = t[j], t[i]
36 }
37
38 // Less implements sort.Interface.
39 func (t Times) Less(i, j int) bool {
40 return t[i].Before(t[j])
41 }
42
43 // ToFloat64 returns a float64 representation of a time.
44 func ToFloat64(t time.Time) float64 {
45 return float64(t.UnixNano())
46 }