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 unix unix.time unix.types ;
7 : timeval>seconds ( timeval -- seconds )
8 [ sec>> ] [ usec>> 1,000,000 / ] bi + ; inline
10 : timeval>duration ( timeval -- duration )
11 timeval>seconds seconds ;
13 : timeval>unix-time ( timeval -- timestamp )
14 [ unix-1970 ] dip timeval>seconds +second ;
16 : timespec>seconds ( timespec -- seconds )
17 [ sec>> ] [ nsec>> 1,000,000,000 / ] bi + ; inline
19 : timespec>duration ( timespec -- duration )
20 timespec>seconds seconds ;
22 : timespec>unix-time ( timespec -- timestamp )
23 [ unix-1970 ] dip timespec>seconds +second ;
25 : get-time ( -- alien )
26 f time time_t <ref> localtime ;
28 : timezone-name ( -- string )
31 M: unix gmt-offset ( -- hours minutes seconds )
32 get-time gmtoff>> 3600 /mod 60 /mod ;
34 : current-timeval ( -- timeval )
35 timeval <struct> f [ gettimeofday io-error ] 2keep drop ;
37 : system-micros ( -- n )
39 [ sec>> 1,000,000 * ] [ usec>> ] bi + ;
42 current-timeval timeval>unix-time ;