-
Notifications
You must be signed in to change notification settings - Fork 4
/
time.go
44 lines (35 loc) · 871 Bytes
/
time.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package utils
import (
"sync/atomic"
"time"
_ "unsafe"
)
/*
Creation Time: 2020 - Apr - 09
Created by: (ehsan)
Maintainers:
1. Ehsan N. Moosa (E2)
Auditor: Ehsan N. Moosa (E2)
*/
var timeInSec int64
func init() {
timeInSec = time.Now().Unix()
go func() {
for {
time.Sleep(time.Second)
atomic.AddInt64(&timeInSec, time.Now().Unix()-atomic.LoadInt64(&timeInSec))
}
}()
}
func TimeUnix() int64 {
return atomic.LoadInt64(&timeInSec)
}
func TimeUnixSubtract(unixTime int64, d time.Duration) int64 {
return int64(time.Duration(unixTime) - d/time.Second)
}
// NanoTime returns the current time in nanoseconds from a monotonic clock.
//go:linkname NanoTime runtime.nanotime
func NanoTime() int64
// CPUTicks is a faster alternative to NanoTime to measure time duration.
//go:linkname CPUTicks runtime.cputicks
func CPUTicks() int64