1 USING: alien alien.c-types kernel math
2 windows windows.kernel32 calendar namespaces ;
5 TUPLE: windows-calendar ;
7 T{ windows-calendar } calendar-impl set-global
9 M: windows-calendar gmt-offset ( -- float )
10 "TIME_ZONE_INFORMATION" <c-object>
11 [ GetTimeZoneInformation win32-error=0/f ] keep
12 [ TIME_ZONE_INFORMATION-Bias ] keep
13 TIME_ZONE_INFORMATION-DaylightBias + 60 /f neg ;
15 : >64bit ( lo hi -- n )
18 : windows-1601 ( -- timestamp )
19 1601 1 1 0 0 0 0 <timestamp> ;
21 : FILETIME>windows-time ( FILETIME -- n )
22 [ FILETIME-dwLowDateTime ] keep
23 FILETIME-dwHighDateTime >64bit ;
25 : windows-time>timestamp ( n -- timestamp )
26 10000000 /i seconds windows-1601 swap +dt ;
28 : windows-time ( -- n )
29 "FILETIME" <c-object> [ GetSystemTimeAsFileTime ] keep
30 FILETIME>windows-time ;
32 : timestamp>windows-time ( timestamp -- n )
33 #! 64bit number representing # of nanoseconds since Jan 1, 1601 (UTC)
34 >gmt windows-1601 timestamp- >bignum 10000000 * ;
36 : windows-time>FILETIME ( n -- FILETIME )
39 [ >r HEX: ffffffff bitand r> set-FILETIME-dwLowDateTime ] 2keep
40 >r -32 shift r> set-FILETIME-dwHighDateTime
43 : timestamp>FILETIME ( timestamp -- FILETIME/f )
44 [ >gmt timestamp>windows-time windows-time>FILETIME ] [ f ] if* ;
46 : FILETIME>timestamp ( FILETIME -- timestamp/f )
47 FILETIME>windows-time windows-time>timestamp ;