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 system clock. This is commonly referred to
10 as Unix time.
12 This clock is affected by discontinuous jumps.
14 """
16 secs = 0
17 nsecs: i32 = 0
18 ok = True
20 c"""
21 struct timespec now;
23 if (clock_gettime(CLOCK_REALTIME, &now) != 0) {
24 ok = false;
25 }
27 secs = now.tv_sec;
28 nsecs = now.tv_nsec;
29 """
31 if not ok:
32 raise TimeError("Failed to get time.")
34 return Time(secs, nsecs)
36test now():
37 assert now().seconds >= 0
38 assert now().nanoseconds >= 0