You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
598 B

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. package binary
  2. import (
  3. "io"
  4. "time"
  5. )
  6. type Time struct {
  7. time.Time
  8. }
  9. func (self Time) Equals(other Binary) bool {
  10. if o, ok := other.(Time); ok {
  11. return self.Equal(o.Time)
  12. } else {
  13. return false
  14. }
  15. }
  16. func (self Time) Less(other Binary) bool {
  17. if o, ok := other.(Time); ok {
  18. return self.Before(o.Time)
  19. } else {
  20. panic("Cannot compare unequal types")
  21. }
  22. }
  23. func (self Time) ByteSize() int {
  24. return 8
  25. }
  26. func (self Time) WriteTo(w io.Writer) (int64, error) {
  27. return Int64(self.Unix()).WriteTo(w)
  28. }
  29. func ReadTime(r io.Reader) Time {
  30. return Time{time.Unix(int64(ReadInt64(r)), 0)}
  31. }