-
Notifications
You must be signed in to change notification settings - Fork 67
/
duration.go
45 lines (35 loc) · 905 Bytes
/
duration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package zed
import (
"github.com/brimdata/zed/pkg/nano"
"github.com/brimdata/zed/zcode"
)
type TypeOfDuration struct{}
func NewDuration(d nano.Duration) Value {
return Value{TypeDuration, EncodeDuration(d)}
}
func EncodeDuration(d nano.Duration) zcode.Bytes {
return EncodeInt(int64(d))
}
func AppendDuration(bytes zcode.Bytes, d nano.Duration) zcode.Bytes {
return AppendInt(bytes, int64(d))
}
func DecodeDuration(zv zcode.Bytes) (nano.Duration, error) {
i, err := DecodeInt(zv)
return nano.Duration(i), err
}
func (t *TypeOfDuration) ID() int {
return IDDuration
}
func (t *TypeOfDuration) String() string {
return "duration"
}
func (t *TypeOfDuration) Marshal(zv zcode.Bytes) (interface{}, error) {
return t.Format(zv), nil
}
func (t *TypeOfDuration) Format(zv zcode.Bytes) string {
d, err := DecodeDuration(zv)
if err != nil {
return badZng(err, t, zv)
}
return d.String()
}