From 0cc0e870519b447436a88dc928a433dd76583a0b Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 1 Sep 2022 09:54:20 +0000 Subject: [PATCH] time: use linux_utc() and linux_now() on freebsd too (more precise, and fixes time_test.v) --- vlib/time/time.c.v | 12 ++++++------ vlib/time/time_test.v | 7 ++++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/vlib/time/time.c.v b/vlib/time/time.c.v index 6c8269eed..38dc7ad32 100644 --- a/vlib/time/time.c.v +++ b/vlib/time/time.c.v @@ -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. diff --git a/vlib/time/time_test.v b/vlib/time/time_test.v index bf26df5ba..16ad54d17 100644 --- a/vlib/time/time_test.v +++ b/vlib/time/time_test.v @@ -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 } -- 2.30.2