calendar.unix: making time conversions a lot faster.

db4
John Benediktsson 2012-07-15 15:16:28 -07:00
parent 28377f49e7
commit 3da5efa25b
1 changed files with 12 additions and 9 deletions

View File

@ -1,23 +1,26 @@
! Copyright (C) 2008 Doug Coleman. ! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.data calendar classes.struct kernel math USING: accessors alien.data calendar calendar.private
system unix unix.time unix.types ; classes.struct kernel math system unix unix.time unix.types ;
IN: calendar.unix IN: calendar.unix
: timeval>seconds ( timeval -- seconds )
[ sec>> ] [ usec>> 1000000000 / ] bi + ; inline
: timeval>duration ( timeval -- duration ) : timeval>duration ( timeval -- duration )
[ sec>> seconds ] [ usec>> microseconds ] bi time+ ; timeval>seconds seconds ;
: timeval>unix-time ( timeval -- timestamp ) : timeval>unix-time ( timeval -- timestamp )
timeval>duration since-1970 ; [ unix-1970 ] dip timeval>seconds +second ;
: timespec>duration ( timespec -- seconds ) : timespec>seconds ( timespec -- seconds )
[ sec>> seconds ] [ nsec>> nanoseconds ] bi time+ ; [ sec>> ] [ nsec>> 1000000000 / ] bi + ; inline
: timespec>nanoseconds ( timespec -- seconds ) : timespec>duration ( timespec -- duration )
[ sec>> 1000000000 * ] [ nsec>> ] bi + ; timespec>seconds seconds ;
: timespec>unix-time ( timespec -- timestamp ) : timespec>unix-time ( timespec -- timestamp )
timespec>duration since-1970 ; [ unix-1970 ] dip timespec>seconds +second ;
: get-time ( -- alien ) : get-time ( -- alien )
f time time_t <ref> localtime ; f time time_t <ref> localtime ;