2015-07-25 15:45:45 -07:00
|
|
|
package wire
|
2014-06-16 16:39:25 -07:00
|
|
|
|
|
|
|
import (
|
2014-07-01 14:50:24 -07:00
|
|
|
"io"
|
|
|
|
"time"
|
2015-08-31 13:00:20 -07:00
|
|
|
|
|
|
|
. "github.com/tendermint/tendermint/common"
|
2014-06-16 16:39:25 -07:00
|
|
|
)
|
|
|
|
|
2015-08-31 13:00:20 -07:00
|
|
|
/*
|
|
|
|
Writes nanoseconds since epoch but with millisecond precision.
|
|
|
|
This is to ease compatibility with Javascript etc.
|
|
|
|
*/
|
2014-07-28 01:41:25 -07:00
|
|
|
|
2014-12-09 18:49:04 -08:00
|
|
|
func WriteTime(t time.Time, w io.Writer, n *int64, err *error) {
|
2015-08-31 13:00:20 -07:00
|
|
|
nanosecs := t.UnixNano()
|
|
|
|
millisecs := nanosecs / 1000000
|
|
|
|
WriteInt64(millisecs*1000000, w, n, err)
|
2014-07-28 01:41:25 -07:00
|
|
|
}
|
|
|
|
|
2014-09-03 19:21:19 -07:00
|
|
|
func ReadTime(r io.Reader, n *int64, err *error) time.Time {
|
|
|
|
t := ReadInt64(r, n, err)
|
2015-08-31 13:00:20 -07:00
|
|
|
if t%1000000 != 0 {
|
|
|
|
PanicSanity("Time cannot have sub-millisecond precision")
|
|
|
|
}
|
2014-10-07 13:39:21 -07:00
|
|
|
return time.Unix(0, t)
|
2014-06-16 16:39:25 -07:00
|
|
|
}
|