mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +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
@ -135,3 +135,15 @@ pub fn (t Time) strftime(fmt string) string {
|
|||||||
C.strftime(&buf[0], usize(sizeof(buf)), fmt_c, tm)
|
C.strftime(&buf[0], usize(sizeof(buf)), fmt_c, tm)
|
||||||
return unsafe { cstring_to_vstring(&char(&buf[0])) }
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -88,11 +88,11 @@ fn darwin_utc() Time {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// dummy to compile with all compilers
|
// dummy to compile with all compilers
|
||||||
pub fn solaris_now() Time {
|
fn solaris_now() Time {
|
||||||
return Time{}
|
return Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// dummy to compile with all compilers
|
// dummy to compile with all compilers
|
||||||
pub fn solaris_utc() Time {
|
fn solaris_utc() Time {
|
||||||
return Time{}
|
return Time{}
|
||||||
}
|
}
|
||||||
|
@ -6,21 +6,21 @@ fn sys_mono_now_darwin() u64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// darwin_now - dummy fn to compile on all platforms/compilers
|
// darwin_now - dummy fn to compile on all platforms/compilers
|
||||||
pub fn darwin_now() Time {
|
fn darwin_now() Time {
|
||||||
return Time{}
|
return Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// solaris_now - dummy fn to compile on all platforms/compilers
|
// solaris_now - dummy fn to compile on all platforms/compilers
|
||||||
pub fn solaris_now() Time {
|
fn solaris_now() Time {
|
||||||
return Time{}
|
return Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// darwin_utc - dummy fn to compile on all platforms/compilers
|
// darwin_utc - dummy fn to compile on all platforms/compilers
|
||||||
pub fn darwin_utc() Time {
|
fn darwin_utc() Time {
|
||||||
return Time{}
|
return Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// solaris_utc - dummy fn to compile on all platforms/compilers
|
// solaris_utc - dummy fn to compile on all platforms/compilers
|
||||||
pub fn solaris_utc() Time {
|
fn solaris_utc() Time {
|
||||||
return Time{}
|
return Time{}
|
||||||
}
|
}
|
||||||
|
@ -95,12 +95,12 @@ fn linux_utc() Time {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// dummy to compile with all compilers
|
// dummy to compile with all compilers
|
||||||
pub fn win_now() Time {
|
fn win_now() Time {
|
||||||
return Time{}
|
return Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// dummy to compile with all compilers
|
// dummy to compile with all compilers
|
||||||
pub fn win_utc() Time {
|
fn win_utc() Time {
|
||||||
return Time{}
|
return Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,15 +125,6 @@ pub fn (d Duration) timespec() C.timespec {
|
|||||||
return ts
|
return ts
|
||||||
}
|
}
|
||||||
|
|
||||||
// zero_timespec returns the calendar time in seconds and nanoseconds of the beginning of the Unix epoch.
|
|
||||||
pub fn zero_timespec() C.timespec {
|
|
||||||
ts := C.timespec{
|
|
||||||
tv_sec: 0
|
|
||||||
tv_nsec: 0
|
|
||||||
}
|
|
||||||
return ts
|
|
||||||
}
|
|
||||||
|
|
||||||
// sleep suspends the execution of the calling thread for a given duration (in nanoseconds).
|
// sleep suspends the execution of the calling thread for a given duration (in nanoseconds).
|
||||||
pub fn sleep(duration Duration) {
|
pub fn sleep(duration Duration) {
|
||||||
mut req := C.timespec{duration / second, duration % second}
|
mut req := C.timespec{duration / second, duration % second}
|
||||||
@ -147,15 +138,3 @@ pub fn sleep(duration Duration) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 > C.INT32_MAX * 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -22,11 +22,11 @@ fn solaris_utc() Time {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// dummy to compile with all compilers
|
// dummy to compile with all compilers
|
||||||
pub fn darwin_now() Time {
|
fn darwin_now() Time {
|
||||||
return Time{}
|
return Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// dummy to compile with all compilers
|
// dummy to compile with all compilers
|
||||||
pub fn darwin_utc() Time {
|
fn darwin_utc() Time {
|
||||||
return Time{}
|
return Time{}
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ fn win_utc() Time {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// unix_time returns Unix time.
|
// unix_time returns Unix time.
|
||||||
pub fn (st SystemTime) unix_time() i64 {
|
fn (st SystemTime) unix_time() i64 {
|
||||||
tt := C.tm{
|
tt := C.tm{
|
||||||
tm_sec: st.second
|
tm_sec: st.second
|
||||||
tm_min: st.minute
|
tm_min: st.minute
|
||||||
@ -184,32 +184,32 @@ pub fn (st SystemTime) unix_time() i64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// dummy to compile with all compilers
|
// dummy to compile with all compilers
|
||||||
pub fn darwin_now() Time {
|
fn darwin_now() Time {
|
||||||
return Time{}
|
return Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// dummy to compile with all compilers
|
// dummy to compile with all compilers
|
||||||
pub fn linux_now() Time {
|
fn linux_now() Time {
|
||||||
return Time{}
|
return Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// dummy to compile with all compilers
|
// dummy to compile with all compilers
|
||||||
pub fn solaris_now() Time {
|
fn solaris_now() Time {
|
||||||
return Time{}
|
return Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// dummy to compile with all compilers
|
// dummy to compile with all compilers
|
||||||
pub fn darwin_utc() Time {
|
fn darwin_utc() Time {
|
||||||
return Time{}
|
return Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// dummy to compile with all compilers
|
// dummy to compile with all compilers
|
||||||
pub fn linux_utc() Time {
|
fn linux_utc() Time {
|
||||||
return Time{}
|
return Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// dummy to compile with all compilers
|
// dummy to compile with all compilers
|
||||||
pub fn solaris_utc() Time {
|
fn solaris_utc() Time {
|
||||||
return Time{}
|
return Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,15 +223,3 @@ pub struct C.timeval {
|
|||||||
pub fn sleep(duration Duration) {
|
pub fn sleep(duration Duration) {
|
||||||
C.Sleep(int(duration / millisecond))
|
C.Sleep(int(duration / millisecond))
|
||||||
}
|
}
|
||||||
|
|
||||||
// some Windows system functions (e.g. `C.WaitForSingleObject()`) accept an `u32`
|
|
||||||
// value as *timeout in milliseconds* with the special value `u32(-1)` meaning "infinite"
|
|
||||||
pub fn (d Duration) sys_milliseconds() u32 {
|
|
||||||
if d >= u32(-1) * millisecond { // treat 4294967295000000 .. C.INT64_MAX as "infinite"
|
|
||||||
return u32(-1)
|
|
||||||
} else if d <= 0 {
|
|
||||||
return 0 // treat negative timeouts as 0 - consistent with Unix behaviour
|
|
||||||
} else {
|
|
||||||
return u32(d / millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user