summaryrefslogtreecommitdiff
path: root/libstd/now.myr
blob: 3d05ca27b2e57773f4a2bf90657d2b1ed47ec504 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use sys

use "types.use"
use "fmt.use"

pkg std =
	const now	: (-> time)
;;

/* microseconds since epoch */
const now = {
	var tm
	var sec
	var nsec

	if sys.clock_gettime(`sys.Clockrealtime, &tm) == 0
		sec = tm.sec
		nsec = tm.nsec castto(uint64)
		-> (sec*1_000_000 + nsec/1000) castto(time)
	else
		-> -1
	;;
}