forked from aerospike/aerospike-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepoc.go
30 lines (27 loc) · 792 Bytes
/
epoc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package types
import (
"math"
"time"
)
const (
// citrusleaf epoc: Jan 01 2010 00:00:00 GMT
CITRUSLEAF_EPOCH = 1262304000
)
// TTL converts an Expiration time from citrusleaf epoc to TTL in seconds.
func TTL(secsFromCitrusLeafEpoc uint32) uint32 {
switch secsFromCitrusLeafEpoc {
// don't convert magic values
case 0: // when set to don't expire, this value is returned
return math.MaxUint32
default:
// Record may not have expired on server, but delay or clock differences may
// cause it to look expired on client. Floor at 1, not 0, to avoid old
// "never expires" interpretation.
now := time.Now().Unix()
expiration := int64(CITRUSLEAF_EPOCH + secsFromCitrusLeafEpoc)
if expiration < 0 || expiration > now {
return uint32(expiration - now)
}
return 1
}
}