factor/basis/calendar/unix/unix.factor

23 lines
676 B
Factor
Raw Normal View History

2008-10-06 19:18:33 -04:00
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
2008-10-06 18:59:20 -04:00
USING: alien alien.c-types alien.syntax arrays calendar
2008-10-06 19:18:33 -04:00
kernel math unix unix.time namespaces system ;
2007-09-20 18:09:08 -04:00
IN: calendar.unix
: timeval>unix-time ( timeval -- timestamp )
[ timeval-sec seconds ] [ timeval-usec microseconds ] bi
time+ since-1970 ;
: timespec>unix-time ( timeval -- timestamp )
[ timespec-sec seconds ] [ timespec-nsec nanoseconds ] bi
time+ since-1970 ;
: get-time ( -- alien )
2007-09-20 18:09:08 -04:00
f time <uint> localtime ;
: timezone-name ( -- string )
2007-09-20 18:09:08 -04:00
get-time tm-zone ;
2008-04-02 19:28:55 -04:00
M: unix gmt-offset ( -- hours minutes seconds )
get-time tm-gmtoff 3600 /mod 60 /mod ;