]> gitweb.factorcode.org Git - factor.git/blob - basis/windows/time/time.factor
Merge branch 'master' of git://factorcode.org/git/factor
[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 windows.kernel32
4 namespaces calendar math.bitwise ;
5 IN: windows.time
6
7 : >64bit ( lo hi -- n )
8     32 shift bitor ;
9
10 : windows-1601 ( -- timestamp )
11     1601 1 1 0 0 0 instant <timestamp> ;
12
13 : FILETIME>windows-time ( FILETIME -- n )
14     [ FILETIME-dwLowDateTime ] keep
15     FILETIME-dwHighDateTime >64bit ;
16
17 : windows-time>timestamp ( n -- timestamp )
18     10000000 /i seconds windows-1601 swap time+ ;
19
20 : windows-time ( -- n )
21     "FILETIME" <c-object> [ GetSystemTimeAsFileTime ] keep
22     FILETIME>windows-time ;
23
24 : timestamp>windows-time ( timestamp -- n )
25     #! 64bit number representing # of nanoseconds since Jan 1, 1601 (UTC)
26     >gmt windows-1601 (time-) 10000000 * >integer ;
27
28 : windows-time>FILETIME ( n -- FILETIME )
29     "FILETIME" <c-object>
30     [
31         [ 32 bits set-FILETIME-dwLowDateTime ] 2keep
32         [ -32 shift ] dip set-FILETIME-dwHighDateTime
33     ] keep ;
34
35 : timestamp>FILETIME ( timestamp -- FILETIME/f )
36     [ >gmt timestamp>windows-time windows-time>FILETIME ] [ f ] if* ;
37
38 : FILETIME>timestamp ( FILETIME -- timestamp/f )
39     FILETIME>windows-time windows-time>timestamp ;