mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
time: reduce the diff for v run cmd/tools/check_os_api_parity time
This commit is contained in:
parent
618961fab5
commit
2cd5b8a86d
6 changed files with 29 additions and 50 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue