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 ;
7 : >64bit ( lo hi -- n )
10 : windows-1601 ( -- timestamp )
11 1601 1 1 0 0 0 instant <timestamp> ;
13 : FILETIME>windows-time ( FILETIME -- n )
14 [ FILETIME-dwLowDateTime ]
15 [ FILETIME-dwHighDateTime ]
18 : windows-time>timestamp ( n -- timestamp )
19 10000000 /i seconds windows-1601 swap time+ ;
21 : windows-time ( -- n )
22 "FILETIME" <c-object> [ GetSystemTimeAsFileTime ] keep
23 FILETIME>windows-time ;
25 : timestamp>windows-time ( timestamp -- n )
26 #! 64bit number representing # of nanoseconds since Jan 1, 1601 (UTC)
27 >gmt windows-1601 (time-) 10000000 * >integer ;
29 : windows-time>FILETIME ( n -- FILETIME )
32 [ [ 32 bits ] dip set-FILETIME-dwLowDateTime ]
33 [ [ -32 shift ] dip set-FILETIME-dwHighDateTime ] 2bi
36 : timestamp>FILETIME ( timestamp -- FILETIME/f )
37 dup [ >gmt timestamp>windows-time windows-time>FILETIME ] when ;
39 : FILETIME>timestamp ( FILETIME -- timestamp/f )
40 FILETIME>windows-time windows-time>timestamp ;