1module time 2 3// linux_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 6[inline] 7fn linux_now() Time { 8 9 // get the high precision time as UTC realtime clock 10 // and use the nanoseconds part 11 mut ts := C.timespec{} 12 C.clock_gettime(C.CLOCK_REALTIME, &ts) 13 14 loc_tm := C.tm{} 15 C.localtime_r(&ts.tv_sec, &loc_tm) 16 17 return convert_ctime(loc_tm, int(ts.tv_nsec/1000)) 18} 19 20[inline] 21fn linux_utc() Time { 22 // get the high precision time as UTC realtime clock 23 // and use the nanoseconds part 24 mut ts := C.timespec{} 25 C.clock_gettime(C.CLOCK_REALTIME, &ts) 26 27 return unix2(int(ts.tv_sec), int(ts.tv_nsec/1000)) 28} 29 30fn sys_mono_now_darwin() u64 { 31 return 0 32} 33 34// dummy to compile with all compilers 35pub fn darwin_now() Time { 36 return Time{} 37} 38 39// dummy to compile with all compilers 40pub fn solaris_now() Time { 41 return Time{} 42} 43 44// dummy to compile with all compilers 45pub fn darwin_utc() Time { 46 return Time{} 47} 48 49// dummy to compile with all compilers 50pub fn solaris_utc() Time { 51 return Time{} 52}