]> gitweb.factorcode.org Git - factor.git/blob - basis/calendar/windows/windows.factor
f866fe81fa55d107754a90bc3a7d922af54350bd
[factor.git] / basis / calendar / windows / windows.factor
1 USING: calendar namespaces alien.c-types system
2 windows.kernel32 kernel math combinators windows.errors
3 accessors classes.struct calendar.format math.functions ;
4 IN: calendar.windows
5
6 : timestamp>SYSTEMTIME ( timestamp -- SYSTEMTIME )
7     {
8         [ year>> ]
9         [ month>> ]
10         [ day-of-week ]
11         [ day>> ]
12         [ hour>> ]
13         [ minute>> ]
14         [
15             second>> dup floor
16             [ nip >integer ]
17             [ - 1000 * >integer ] 2bi
18         ]
19     } cleave \ SYSTEMTIME <struct-boa> ;
20
21 : SYSTEMTIME>timestamp ( SYSTEMTIME -- timestamp )
22     {
23         [ wYear>> ]
24         [ wMonth>> ]
25         [ wDay>> ]
26         [ wHour>> ]
27         [ wMinute>> ]
28         [ [ wSecond>> ] [ wMilliseconds>> 1000 / ] bi + ]
29     } cleave instant <timestamp> ;
30
31 M: windows gmt-offset ( -- hours minutes seconds )
32     TIME_ZONE_INFORMATION <struct>
33     dup GetTimeZoneInformation {
34         { TIME_ZONE_ID_INVALID [ win32-error ] }
35         { TIME_ZONE_ID_UNKNOWN [ Bias>> ] }
36         { TIME_ZONE_ID_STANDARD [ Bias>> ] }
37         { TIME_ZONE_ID_DAYLIGHT [ [ Bias>> ] [ DaylightBias>> ] bi + ] }
38     } case neg 60 /mod 0 ;
39
40 M: windows gmt
41     SYSTEMTIME <struct> [ GetSystemTime ] keep SYSTEMTIME>timestamp ;