time: reduce the diff for v run cmd/tools/check_os_api_parity time

This commit is contained in:
Delyan Angelov 2023-07-31 11:02:10 +03:00
parent 618961fab5
commit 2cd5b8a86d
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED
6 changed files with 29 additions and 50 deletions

View file

@ -135,3 +135,15 @@ pub fn (t Time) strftime(fmt string) string {
C.strftime(&buf[0], usize(sizeof(buf)), fmt_c, tm)
return unsafe { cstring_to_vstring(&char(&buf[0])) }
}
// some *nix system functions (e.g. `C.poll()`, C.epoll_wait()) accept an `int`
// value as *timeout in milliseconds* with the special value `-1` meaning "infinite"
pub fn (d Duration) sys_milliseconds() int {
if d > 2147483647 * millisecond { // treat 2147483647000001 .. C.INT64_MAX as "infinite"
return -1
} else if d <= 0 {
return 0 // treat negative timeouts as 0 - consistent with Unix behaviour
} else {
return int(d / millisecond)
}
}