1
0
mirror of https://git.zx2c4.com/wireguard-go synced 2024-11-15 09:15:14 +01:00
wireguard-go/tai64.go

29 lines
492 B
Go
Raw Normal View History

2017-06-23 13:41:59 +02:00
package main
import (
2017-06-24 15:34:17 +02:00
"bytes"
2017-06-23 13:41:59 +02:00
"encoding/binary"
"time"
)
const (
TAI64NBase = uint64(4611686018427387914)
TAI64NSize = 12
)
type TAI64N [TAI64NSize]byte
func Timestamp() TAI64N {
var tai64n TAI64N
now := time.Now()
secs := TAI64NBase + uint64(now.Unix())
nano := uint32(now.UnixNano())
binary.BigEndian.PutUint64(tai64n[:], secs)
binary.BigEndian.PutUint32(tai64n[8:], nano)
return tai64n
}
2017-06-24 15:34:17 +02:00
func (t1 *TAI64N) After(t2 TAI64N) bool {
return bytes.Compare(t1[:], t2[:]) > 0
}