Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from . import Time
2from . import TimeError
4c"""source-before-namespace
5#include <ctime>
6"""
8func now() -> Time:
9 """Get the current time of steady (monotonic) clock.
11 This clock is not affected by discontinuous jumps.
13 """
15 secs = 0
16 nsecs: i32 = 0
17 ok = True
19 c"""
20 struct timespec now;
22 if (clock_gettime(CLOCK_MONOTONIC, &now) != 0) {
23 ok = false;
24 }
26 secs = now.tv_sec;
27 nsecs = now.tv_nsec;
28 """
30 if not ok:
31 raise TimeError("Failed to get time.")
33 return Time(secs, nsecs)
35test now():
36 assert now().seconds >= 0
37 assert now().nanoseconds >= 0