tendermint/binary/time.go

39 lines
598 B
Go
Raw Normal View History

2014-06-16 16:39:25 -07:00
package binary
import (
2014-07-01 14:50:24 -07:00
"io"
"time"
2014-06-16 16:39:25 -07:00
)
type Time struct {
2014-07-01 14:50:24 -07:00
time.Time
2014-06-16 16:39:25 -07:00
}
func (self Time) Equals(other Binary) bool {
2014-07-01 14:50:24 -07:00
if o, ok := other.(Time); ok {
return self.Equal(o.Time)
} else {
return false
}
2014-06-16 16:39:25 -07:00
}
func (self Time) Less(other Binary) bool {
2014-07-01 14:50:24 -07:00
if o, ok := other.(Time); ok {
return self.Before(o.Time)
} else {
panic("Cannot compare unequal types")
}
2014-06-16 16:39:25 -07:00
}
func (self Time) ByteSize() int {
2014-07-01 14:50:24 -07:00
return 8
2014-06-16 16:39:25 -07:00
}
func (self Time) WriteTo(w io.Writer) (int64, error) {
2014-07-01 14:50:24 -07:00
return Int64(self.Unix()).WriteTo(w)
2014-06-16 16:39:25 -07:00
}
func ReadTime(r io.Reader) Time {
2014-07-01 14:50:24 -07:00
return Time{time.Unix(int64(ReadInt64(r)), 0)}
2014-06-16 16:39:25 -07:00
}