Use server time as a default everywhere
This commit is contained in:
parent
fd6579114c
commit
c515ef8dc5
6 changed files with 47 additions and 25 deletions
16
time.go
16
time.go
|
|
@ -7,18 +7,26 @@ import (
|
|||
// UpdateTime update cached time
|
||||
func (o *OpenPGP) UpdateTime(newTime int64) {
|
||||
o.latestServerTime = newTime
|
||||
o.latestClientTime = time.Now()
|
||||
}
|
||||
|
||||
//GetTime get latest cached time
|
||||
func (o *OpenPGP) GetTime() int64 {
|
||||
return o.latestServerTime
|
||||
return o.getNow().Unix()
|
||||
}
|
||||
|
||||
func (o *OpenPGP) getNow() time.Time {
|
||||
|
||||
if o.latestServerTime > 0 {
|
||||
return time.Unix(o.latestServerTime, 0)
|
||||
if o.latestServerTime > 0 && !o.latestClientTime.IsZero() {
|
||||
// Sub is monotome, it uses a monotime time clock in this case instead of the wall clock
|
||||
extrapolate := int64(o.latestClientTime.Sub(time.Now()).Seconds())
|
||||
return time.Unix(o.latestServerTime + extrapolate, 0)
|
||||
}
|
||||
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
func (o *OpenPGP) getTimeGenerator() func() time.Time {
|
||||
return func() time.Time {
|
||||
return o.getNow()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue