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.

27 lines
574 B

10 years ago
10 years ago
10 years ago
10 years ago
  1. package wire
  2. import (
  3. "io"
  4. "time"
  5. . "github.com/tendermint/tendermint/common"
  6. )
  7. /*
  8. Writes nanoseconds since epoch but with millisecond precision.
  9. This is to ease compatibility with Javascript etc.
  10. */
  11. func WriteTime(t time.Time, w io.Writer, n *int64, err *error) {
  12. nanosecs := t.UnixNano()
  13. millisecs := nanosecs / 1000000
  14. WriteInt64(millisecs*1000000, w, n, err)
  15. }
  16. func ReadTime(r io.Reader, n *int64, err *error) time.Time {
  17. t := ReadInt64(r, n, err)
  18. if t%1000000 != 0 {
  19. PanicSanity("Time cannot have sub-millisecond precision")
  20. }
  21. return time.Unix(0, t)
  22. }