]> gitweb.factorcode.org Git - factor.git/blob - basis/unix/time/time.factor
classes.struct: moving to new/boa instead of <struct>/<struct-boa>
[factor.git] / basis / unix / time / time.factor
1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.c-types alien.syntax
4 classes.struct kernel math unix.types ;
5 IN: unix.time
6
7 STRUCT: timeval
8     { sec long }
9     { usec long } ;
10
11 STRUCT: timespec
12     { sec time_t }
13     { nsec long } ;
14
15 : <timeval> ( sec usec -- timeval )
16     timeval new
17         swap >>usec
18         swap >>sec ; inline
19
20 : make-timeval ( us -- timeval )
21     [ timeval new ] dip [
22         1000000 /mod [ >>sec ] [ >>usec ] bi*
23     ] unless-zero ;
24
25 : make-timespec ( nanos -- timespec )
26     [ timespec new ] dip [
27         1000000000 /mod [ >>sec ] [ >>nsec ] bi*
28     ] unless-zero ;
29
30 STRUCT: timezone
31     { minuteswest int }
32     { dsttime int } ;
33
34 STRUCT: tm
35     { sec int }
36     { min int }
37     { hour int }
38     { mday int }
39     { mon int }
40     { year int }
41     { wday int }
42     { yday int }
43     { isdst int }
44     { gmtoff long }
45     { zone c-string } ;
46
47 FUNCTION: time_t time ( time_t* t )
48 FUNCTION: tm* localtime ( time_t* clock )
49 FUNCTION: int gettimeofday ( timespec* TP, void* TZP )
50 FUNCTION: int settimeofday ( timeval* TP, timezone* TZP )
51 FUNCTION: int adjtime ( timeval* delta, timeval* olddelta )