v / vlib / time / time_solaris.c.v
32 lines · 28 sloc · 955 bytes · 5d979e313177cbe023e15a958a8dd7261f49402b
Raw
1module time
2
3// solaris_now returns the local time with high precision for most os:es
4// this should be implemented properly with support for leap seconds.
5// It uses the realtime clock to get and converts it to local time
6fn solaris_now() Time {
7 // get the high precision time as UTC realtime clock
8 // and use the nanoseconds part
9 mut ts := C.timespec{}
10 C.clock_gettime(C.CLOCK_REALTIME, &ts)
11 loc_tm := C.tm{}
12 C.localtime_r(voidptr(&ts.tv_sec), &loc_tm)
13 return convert_ctime_with_unix(loc_tm, int(ts.tv_nsec), i64(ts.tv_sec) + i64(loc_tm.tm_gmtoff))
14}
15
16fn solaris_utc() Time {
17 // get the high precision time as UTC realtime clock
18 // and use the nanoseconds part
19 mut ts := C.timespec{}
20 C.clock_gettime(C.CLOCK_REALTIME, &ts)
21 return unix_nanosecond(i64(ts.tv_sec), int(ts.tv_nsec))
22}
23
24// dummy to compile with all compilers
25fn darwin_now() Time {
26 return Time{}
27}
28
29// dummy to compile with all compilers
30fn darwin_utc() Time {
31 return Time{}
32}
33