]> gitweb.factorcode.org Git - factor.git/blob - basis/windows/time/time.factor
calendar: change >gmt, >local-time to clone.
[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: accessors alien alien.c-types calendar calendar.private
4 classes.struct kernel math math.bitwise namespaces
5 windows.errors windows.handles windows.kernel32 windows.types ;
6 IN: windows.time
7
8 : >64bit ( lo hi -- n )
9     32 shift bitor ; inline
10
11 : windows-1601 ( -- timestamp ) 1601 <year-gmt> ;
12
13 : FILETIME>windows-time ( FILETIME -- n )
14     [ dwLowDateTime>> ] [ dwHighDateTime>> ] bi >64bit ;
15
16 : windows-time>timestamp ( n -- timestamp )
17     [ windows-1601 ] dip 10,000,000 /i +second ;
18
19 : windows-time ( -- n )
20     FILETIME <struct> [ GetSystemTimeAsFileTime ] keep
21     FILETIME>windows-time ;
22
23 : timestamp>windows-time ( timestamp -- n )
24     ! 64bit number representing # of nanoseconds since Jan 1, 1601 (UTC)
25     >gmt windows-1601 (time-) 10,000,000 * >integer ;
26
27 : windows-time>FILETIME ( n -- FILETIME )
28     [ FILETIME <struct> ] dip
29     [ 32 bits >>dwLowDateTime ] [ -32 shift >>dwHighDateTime ] bi ;
30
31 : timestamp>FILETIME ( timestamp -- FILETIME/f )
32     dup [ >gmt timestamp>windows-time windows-time>FILETIME ] when ;
33
34 : FILETIME>timestamp ( FILETIME -- timestamp/f )
35     FILETIME>windows-time windows-time>timestamp ;