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 system clock. This is commonly referred to 

10 as Unix time. 

11 

12 This clock is affected by discontinuous jumps. 

13 

14 """ 

15 

16 secs = 0 

17 nsecs: i32 = 0 

18 ok = True 

19 

20 c""" 

21 struct timespec now; 

22 

23 if (clock_gettime(CLOCK_REALTIME, &now) != 0) { 

24 ok = false; 

25 } 

26 

27 secs = now.tv_sec; 

28 nsecs = now.tv_nsec; 

29 """ 

30 

31 if not ok: 

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

33 

34 return Time(secs, nsecs) 

35 

36test now(): 

37 assert now().seconds >= 0 

38 assert now().nanoseconds >= 0