factor/basis/windows/time/time.factor

36 lines
1.2 KiB
Factor
Raw Normal View History

2008-03-04 23:32:12 -05:00
! Copyright (C) 2007 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: alien alien.c-types kernel math windows.errors
2009-11-21 18:24:37 -05:00
windows.kernel32 windows.types namespaces calendar math.bitwise
accessors classes.struct windows.handles ;
2008-03-04 23:32:12 -05:00
IN: windows.time
: >64bit ( lo hi -- n )
32 shift bitor ; inline
2008-03-04 23:32:12 -05:00
2010-01-14 18:20:30 -05:00
: windows-1601 ( -- timestamp ) 1601 <year-gmt> ;
2008-03-04 23:32:12 -05:00
: FILETIME>windows-time ( FILETIME -- n )
[ dwLowDateTime>> ] [ dwHighDateTime>> ] bi >64bit ;
2008-03-04 23:32:12 -05:00
: windows-time>timestamp ( n -- timestamp )
10000000 /i seconds windows-1601 swap time+ ;
: windows-time ( -- n )
FILETIME <struct> [ GetSystemTimeAsFileTime ] keep
2008-03-04 23:32:12 -05:00
FILETIME>windows-time ;
: timestamp>windows-time ( timestamp -- n )
#! 64bit number representing # of nanoseconds since Jan 1, 1601 (UTC)
>gmt windows-1601 (time-) 10000000 * >integer ;
: windows-time>FILETIME ( n -- FILETIME )
[ FILETIME <struct> ] dip
[ 32 bits >>dwLowDateTime ] [ -32 shift >>dwHighDateTime ] bi ;
2008-03-04 23:32:12 -05:00
: timestamp>FILETIME ( timestamp -- FILETIME/f )
dup [ >gmt timestamp>windows-time windows-time>FILETIME ] when ;
2008-03-04 23:32:12 -05:00
: FILETIME>timestamp ( FILETIME -- timestamp/f )
FILETIME>windows-time windows-time>timestamp ;