diff --git a/lib/chibi/time.module b/lib/chibi/time.module index 3bf62fa6..bdf219cc 100644 --- a/lib/chibi/time.module +++ b/lib/chibi/time.module @@ -2,7 +2,7 @@ (module (chibi time) (export current-seconds get-time-of-day set-time-of-day! seconds->time seconds->string time->seconds time->string - timeval-seconds timeval-microseconds + make-timeval timeval-seconds timeval-microseconds timezone-offset timezone-dst-time time-second time-minute time-hour time-day time-month time-year time-day-of-week time-day-of-year time-dst? diff --git a/lib/chibi/time.stub b/lib/chibi/time.stub index 88a192c9..7746ee6c 100644 --- a/lib/chibi/time.stub +++ b/lib/chibi/time.stub @@ -19,6 +19,7 @@ (define-c-struct timeval predicate: timeval? + constructor: (make-timeval tv_sec tv_usec) (time_t tv_sec timeval-seconds) (int tv_usec timeval-microseconds)) diff --git a/lib/srfi/18.module b/lib/srfi/18.module index eabe8b8c..031c1477 100644 --- a/lib/srfi/18.module +++ b/lib/srfi/18.module @@ -15,7 +15,8 @@ join-timeout-exception? abandoned-mutex-exception? terminated-thread-exception? uncaught-exception? uncaught-exception-reason) - (import (scheme) (srfi 9) (chibi ast) (chibi time)) + (import (scheme) (srfi 9) (chibi ast) + (except (chibi time) time->seconds seconds->time)) (include "18/types.scm") (include-shared "18/threads") (include "18/interface.scm")) diff --git a/lib/srfi/18/interface.scm b/lib/srfi/18/interface.scm index dd1a46dc..84041576 100644 --- a/lib/srfi/18/interface.scm +++ b/lib/srfi/18/interface.scm @@ -40,6 +40,12 @@ (define current-time get-time-of-day) (define time? timeval?) +(define (time->seconds x) + (timeval-seconds (if (pair? x) (car x) x))) + +(define (seconds->time x) + (make-timeval (if (inexact? x) (inexact->exact x) x) 0)) + (define (join-timeout-exception? x) (and (exception? x) (equal? (exception-message x) "timed out waiting for thread")))