add timespec>timestamp word
parent
e0d6aadc8e
commit
b168d75a46
|
@ -402,9 +402,16 @@ PRIVATE>
|
||||||
: time-since-midnight ( timestamp -- duration )
|
: time-since-midnight ( timestamp -- duration )
|
||||||
dup midnight time- ;
|
dup midnight time- ;
|
||||||
|
|
||||||
|
: since-1970 ( time -- timestamp )
|
||||||
|
unix-1970 time+ >local-time ;
|
||||||
|
|
||||||
: timeval>unix-time ( timeval -- timestamp )
|
: timeval>unix-time ( timeval -- timestamp )
|
||||||
[ timeval-sec seconds ] [ timeval-usec microseconds ] bi
|
[ timeval-sec seconds ] [ timeval-usec microseconds ] bi
|
||||||
time+ unix-1970 time+ >local-time ;
|
time+ since-1970 ;
|
||||||
|
|
||||||
|
: timespec>unix-time ( timeval -- timestamp )
|
||||||
|
[ timespec-sec seconds ] [ timespec-nsec nanoseconds ] bi
|
||||||
|
time+ since-1970 ;
|
||||||
|
|
||||||
M: timestamp sleep-until timestamp>millis sleep-until ;
|
M: timestamp sleep-until timestamp>millis sleep-until ;
|
||||||
|
|
||||||
|
|
|
@ -10,3 +10,13 @@ C-STRUCT: timeval
|
||||||
"timeval" <c-object>
|
"timeval" <c-object>
|
||||||
[ set-timeval-usec ] keep
|
[ set-timeval-usec ] keep
|
||||||
[ set-timeval-sec ] keep ;
|
[ set-timeval-sec ] keep ;
|
||||||
|
|
||||||
|
C-STRUCT: timespec
|
||||||
|
{ "time_t" "sec" }
|
||||||
|
{ "long" "nsec" } ;
|
||||||
|
|
||||||
|
: make-timespec ( ms -- timespec )
|
||||||
|
1000 /mod 1000000 *
|
||||||
|
"timespec" <c-object>
|
||||||
|
[ set-timespec-nsec ] keep
|
||||||
|
[ set-timespec-sec ] keep ;
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
|
|
||||||
USING: kernel alien.syntax alien.c-types math ;
|
USING: kernel alien.syntax alien.c-types math ;
|
||||||
|
|
||||||
IN: unix.time
|
IN: unix.time
|
||||||
|
|
||||||
TYPEDEF: uint time_t
|
TYPEDEF: uint time_t
|
||||||
|
@ -18,16 +16,6 @@ C-STRUCT: tm
|
||||||
{ "long" "gmtoff" } ! Seconds: 0-59 (K&R says 0-61?)
|
{ "long" "gmtoff" } ! Seconds: 0-59 (K&R says 0-61?)
|
||||||
{ "char*" "zone" } ;
|
{ "char*" "zone" } ;
|
||||||
|
|
||||||
C-STRUCT: timespec
|
|
||||||
{ "time_t" "sec" }
|
|
||||||
{ "long" "nsec" } ;
|
|
||||||
|
|
||||||
: make-timespec ( ms -- timespec )
|
|
||||||
1000 /mod 1000000 *
|
|
||||||
"timespec" <c-object>
|
|
||||||
[ set-timespec-nsec ] keep
|
|
||||||
[ set-timespec-sec ] keep ;
|
|
||||||
|
|
||||||
FUNCTION: time_t time ( time_t* t ) ;
|
FUNCTION: time_t time ( time_t* t ) ;
|
||||||
FUNCTION: tm* localtime ( time_t* clock ) ;
|
FUNCTION: tm* localtime ( time_t* clock ) ;
|
||||||
FUNCTION: int gettimeofday ( timespec* TP, void* TZP ) ;
|
FUNCTION: int gettimeofday ( timespec* TP, void* TZP ) ;
|
||||||
|
|
Loading…
Reference in New Issue