]> gitweb.factorcode.org Git - factor.git/blob - basis/calendar/unix/unix.factor
scrub memory>struct calls made redundant
[factor.git] / basis / calendar / unix / unix.factor
1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien alien.c-types alien.syntax arrays calendar
4 kernel math unix unix.time unix.types namespaces system
5 accessors classes.struct ;
6 IN: calendar.unix
7
8 : timeval>seconds ( timeval -- seconds )
9     [ sec>> seconds ] [ usec>> microseconds ] bi time+ ;
10
11 : timeval>unix-time ( timeval -- timestamp )
12     timeval>seconds since-1970 ;
13
14 : timespec>seconds ( timespec -- seconds )
15     [ sec>> seconds ] [ nsec>> nanoseconds ] bi time+ ;
16
17 : timespec>nanoseconds ( timespec -- seconds )
18     [ sec>> 1000000000 * ] [ nsec>> ] bi + ;
19
20 : timespec>unix-time ( timespec -- timestamp )
21     timespec>seconds since-1970 ;
22
23 : get-time ( -- alien )
24     f time <time_t> localtime ;
25
26 : timezone-name ( -- string )
27     get-time zone>> ;
28
29 M: unix gmt-offset ( -- hours minutes seconds )
30     get-time gmtoff>> 3600 /mod 60 /mod ;