Hide keyboard shortcuts

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 

3 

4c"""source-before-namespace 

5#include <ctime> 

6""" 

7 

8func now() -> Time: 

9 """Get the current time of steady (monotonic) clock. 

10 

11 This clock is not affected by discontinuous jumps. 

12 

13 """ 

14 

15 secs = 0 

16 nsecs: i32 = 0 

17 ok = True 

18 

19 c""" 

20 struct timespec now; 

21 

22 if (clock_gettime(CLOCK_MONOTONIC, &now) != 0) { 

23 ok = false; 

24 } 

25 

26 secs = now.tv_sec; 

27 nsecs = now.tv_nsec; 

28 """ 

29 

30 if not ok: 

31 raise TimeError("Failed to get time.") 

32 

33 return Time(secs, nsecs) 

34 

35test now(): 

36 assert now().seconds >= 0 

37 assert now().nanoseconds >= 0