-
Notifications
You must be signed in to change notification settings - Fork 9
/
time.go
59 lines (48 loc) · 1.29 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package wasi
import (
"fmt"
"time"
)
// Timestamp is a timestamp in nanoseconds.
type Timestamp uint64
func (t Timestamp) Duration() time.Duration {
return time.Duration(t)
}
func (t Timestamp) Time() time.Time {
return time.Unix(0, int64(t)).UTC()
}
func (t Timestamp) String() string {
return t.Time().Format(time.RFC3339Nano)
}
// ClockID is an identifier for clocks.
type ClockID uint32
const (
// Realtime is the clock measuring real time. Time value zero corresponds
// with 1970-01-01T00:00:00Z.
Realtime ClockID = iota
// Monotonic is the store-wide monotonic clock, which is defined as a clock
// measuring real time, whose value cannot be adjusted and which cannot
// have negative clock jumps. The epoch of this clock is undefined. The
// absolute time value of this clock therefore has no meaning.
Monotonic
// ProcessCPUTimeID is the CPU-time clock associated with the current
// process.
ProcessCPUTimeID
// ThreadCPUTimeID is the CPU-time clock associated with the current
// thread.
ThreadCPUTimeID
)
func (c ClockID) String() string {
switch c {
case Realtime:
return "Realtime"
case Monotonic:
return "Monotonic"
case ProcessCPUTimeID:
return "ProcessCPUTimeID"
case ThreadCPUTimeID:
return "ThreadCPUTimeID"
default:
return fmt.Sprintf("ClockID(%d)", c)
}
}