v
Зеркало из https://github.com/vlang/v
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
9mut ts := C.timespec{}
10C.clock_gettime(C.CLOCK_REALTIME, &ts)
11loc_tm := C.tm{}
12C.localtime_r(voidptr(&ts.tv_sec), &loc_tm)
13return convert_ctime(loc_tm, int(ts.tv_nsec))
14}
15
16fn solaris_utc() Time {
17// get the high precision time as UTC realtime clock
18// and use the nanoseconds part
19mut ts := C.timespec{}
20C.clock_gettime(C.CLOCK_REALTIME, &ts)
21return unix_nanosecond(i64(ts.tv_sec), int(ts.tv_nsec))
22}
23
24// dummy to compile with all compilers
25fn darwin_now() Time {
26return Time{}
27}
28
29// dummy to compile with all compilers
30fn darwin_utc() Time {
31return Time{}
32}
33