mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
time: use linux_utc() and linux_now() on freebsd too (more precise, and fixes time_test.v)
This commit is contained in:
parent
23e8fca4f9
commit
0cc0e87051
@ -31,14 +31,14 @@ pub fn now() Time {
|
||||
$if solaris {
|
||||
return solaris_now()
|
||||
}
|
||||
$if linux || android {
|
||||
return linux_now()
|
||||
}
|
||||
return linux_now()
|
||||
/*
|
||||
// defaults to most common feature, the microsecond precision is not available
|
||||
// in this API call
|
||||
t := C.time(0)
|
||||
now := C.localtime(&t)
|
||||
return convert_ctime(*now, 0)
|
||||
*/
|
||||
}
|
||||
|
||||
// utc returns the current UTC time.
|
||||
@ -52,14 +52,14 @@ pub fn utc() Time {
|
||||
$if solaris {
|
||||
return solaris_utc()
|
||||
}
|
||||
$if linux || android {
|
||||
return linux_utc()
|
||||
}
|
||||
return linux_utc()
|
||||
/*
|
||||
// defaults to most common feature, the microsecond precision is not available
|
||||
// in this API call
|
||||
t := C.time(0)
|
||||
_ = C.time(&t)
|
||||
return unix2(i64(t), 0)
|
||||
*/
|
||||
}
|
||||
|
||||
// new_time returns a time struct with calculated Unix time.
|
||||
|
@ -210,16 +210,21 @@ fn test_unix_time() {
|
||||
t1 := time.utc()
|
||||
time.sleep(50 * time.millisecond)
|
||||
t2 := time.utc()
|
||||
eprintln('t1: $t1')
|
||||
eprintln('t2: $t2')
|
||||
ut1 := t1.unix_time()
|
||||
ut2 := t2.unix_time()
|
||||
eprintln('ut1: $ut1')
|
||||
eprintln('ut2: $ut2')
|
||||
assert ut2 - ut1 < 2
|
||||
//
|
||||
utm1 := t1.unix_time_milli()
|
||||
utm2 := t2.unix_time_milli()
|
||||
eprintln('utm1: $utm1')
|
||||
eprintln('utm2: $utm2')
|
||||
assert (utm1 - ut1 * 1000) < 1000
|
||||
assert (utm2 - ut2 * 1000) < 1000
|
||||
//
|
||||
// println('utm1: $utm1 | utm2: $utm2')
|
||||
assert utm2 - utm1 > 2
|
||||
assert utm2 - utm1 < 999
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user