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 accessors
8 : >64bit ( lo hi -- n )
9 32 shift bitor ; inline
11 : windows-1601 ( -- timestamp )
12 1601 1 1 0 0 0 instant <timestamp> ;
14 : FILETIME>windows-time ( FILETIME -- n )
15 [ dwLowDateTime>> ] [ dwHighDateTime>> ] bi >64bit ;
17 : windows-time>timestamp ( n -- timestamp )
18 10000000 /i seconds windows-1601 swap time+ ;
20 : windows-time ( -- n )
21 FILETIME <struct> [ 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 )
29 [ FILETIME <struct> ] dip
30 [ 32 bits >>dwLowDateTime ] [ -32 shift >>dwHighDateTime ] bi ;
32 : timestamp>FILETIME ( timestamp -- FILETIME/f )
33 dup [ >gmt timestamp>windows-time windows-time>FILETIME ] when ;
35 : FILETIME>timestamp ( FILETIME -- timestamp/f )
36 FILETIME>windows-time windows-time>timestamp ;