1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.data calendar calendar.private
4 classes.struct kernel math system libc unix unix.time unix.types ;
7 : timeval>seconds ( timeval -- seconds )
8 [ sec>> ] [ usec>> 1,000,000 / ] bi + ; inline
10 : timeval>micros ( timeval -- micros )
11 [ sec>> 1,000,000 * ] [ usec>> ] bi + ; inline
13 : timeval>duration ( timeval -- duration )
14 timeval>seconds seconds ; inline
16 : timeval>unix-time ( timeval -- timestamp )
17 [ unix-1970 ] dip timeval>seconds +second ; inline
19 : timespec>seconds ( timespec -- seconds )
20 [ sec>> ] [ nsec>> 1,000,000,000 / ] bi + ; inline
22 : timespec>duration ( timespec -- duration )
23 timespec>seconds seconds ; inline
25 : timespec>unix-time ( timespec -- timestamp )
26 [ unix-1970 ] dip timespec>seconds +second ; inline
28 : get-time ( -- alien )
29 f time time_t <ref> localtime ; inline
31 : timezone-name ( -- string )
35 get-time gmtoff>> 3600 /mod 60 /mod ;
37 : current-timeval ( -- timeval )
38 timeval new [ f gettimeofday io-error ] keep ; inline
40 : system-micros ( -- n )
41 current-timeval timeval>micros ;
44 current-timeval timeval>unix-time ;