]> gitweb.factorcode.org Git - factor.git/blob - basis/windows/time/time.factor
Merge branch 'master' into redis
[factor.git] / basis / windows / time / time.factor
1 ! Copyright (C) 2007 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien alien.c-types kernel math windows.errors
4 windows.kernel32 namespaces calendar math.bitwise ;
5 IN: windows.time
6
7 : >64bit ( lo hi -- n )
8     32 shift bitor ; inline
9
10 : windows-1601 ( -- timestamp )
11     1601 1 1 0 0 0 instant <timestamp> ;
12
13 : FILETIME>windows-time ( FILETIME -- n )
14     [ FILETIME-dwLowDateTime ]
15     [ FILETIME-dwHighDateTime ]
16     bi >64bit ;
17
18 : windows-time>timestamp ( n -- timestamp )
19     10000000 /i seconds windows-1601 swap time+ ;
20
21 : windows-time ( -- n )
22     "FILETIME" <c-object> [ GetSystemTimeAsFileTime ] keep
23     FILETIME>windows-time ;
24
25 : timestamp>windows-time ( timestamp -- n )
26     #! 64bit number representing # of nanoseconds since Jan 1, 1601 (UTC)
27     >gmt windows-1601 (time-) 10000000 * >integer ;
28
29 : windows-time>FILETIME ( n -- FILETIME )
30     "FILETIME" <c-object>
31     [
32         [ [ 32 bits ] dip set-FILETIME-dwLowDateTime ]
33         [ [ -32 shift ] dip set-FILETIME-dwHighDateTime ] 2bi
34     ] keep ;
35
36 : timestamp>FILETIME ( timestamp -- FILETIME/f )
37     dup [ >gmt timestamp>windows-time windows-time>FILETIME ] when ;
38
39 : FILETIME>timestamp ( FILETIME -- timestamp/f )
40     FILETIME>windows-time windows-time>timestamp ;