[flowrate] refactor clock functions (Refs #16)

this commit does not fix the original bug
This commit is contained in:
Anton Kaliaev 2017-05-23 15:19:48 +02:00
parent 306795ae1d
commit 6b10432463
No known key found for this signature in database
GPG Key ID: 7B6881D965918214
1 changed files with 3 additions and 3 deletions

View File

@ -15,16 +15,16 @@ const clockRate = 20 * time.Millisecond
// czero is the process start time rounded down to the nearest clockRate
// increment.
var czero = time.Duration(time.Now().UnixNano()) / clockRate * clockRate
var czero = time.Now().Round(clockRate)
// clock returns a low resolution timestamp relative to the process start time.
func clock() time.Duration {
return time.Duration(time.Now().UnixNano())/clockRate*clockRate - czero
return time.Now().Round(clockRate).Sub(czero)
}
// clockToTime converts a clock() timestamp to an absolute time.Time value.
func clockToTime(c time.Duration) time.Time {
return time.Unix(0, int64(czero+c))
return czero.Add(c)
}
// clockRound returns d rounded to the nearest clockRate increment.