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 ] keep
15 FILETIME-dwHighDateTime >64bit ;
17 : windows-time>timestamp ( n -- timestamp )
18 10000000 /i seconds windows-1601 swap time+ ;
20 : windows-time ( -- n )
21 "FILETIME" <c-object> [ GetSystemTimeAsFileTime ] keep
22 FILETIME>windows-time ;
24 : timestamp>windows-time ( timestamp -- n )
25 #! 64bit number representing # of nanoseconds since Jan 1, 1601 (UTC)
26 >gmt windows-1601 (time-) 10000000 * >integer ;
28 : windows-time>FILETIME ( n -- FILETIME )
31 [ 32 bits set-FILETIME-dwLowDateTime ] 2keep
32 [ -32 shift ] dip set-FILETIME-dwHighDateTime
35 : timestamp>FILETIME ( timestamp -- FILETIME/f )
36 [ >gmt timestamp>windows-time windows-time>FILETIME ] [ f ] if* ;
38 : FILETIME>timestamp ( FILETIME -- timestamp/f )
39 FILETIME>windows-time windows-time>timestamp ;