]> gitweb.factorcode.org Git - factor.git/blob - basis/calendar/windows/windows.factor
Implement set-time on Windows
[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 M: windows gmt-offset ( -- hours minutes seconds )
7     TIME_ZONE_INFORMATION <struct>
8     dup GetTimeZoneInformation {
9         { TIME_ZONE_ID_INVALID [ win32-error-string throw ] }
10         { TIME_ZONE_ID_UNKNOWN [ Bias>> ] }
11         { TIME_ZONE_ID_STANDARD [ Bias>> ] }
12         { TIME_ZONE_ID_DAYLIGHT [ [ Bias>> ] [ DaylightBias>> ] bi + ] }
13     } case neg 60 /mod 0 ;
14
15 : timestamp>SYSTEMTIME ( timestamp -- SYSTEMTIME )
16     {
17         [ year>> ]
18         [ month>> ]
19         [ day-of-week ]
20         [ day>> ]
21         [ hour>> ]
22         [ minute>> ]
23         [
24             second>> dup floor
25             [ nip >integer ]
26             [ - 1000 * >integer ] 2bi
27         ]
28     } cleave \ SYSTEMTIME <struct-boa> ;
29
30 : SYSTEMTIME>timestamp ( SYSTEMTIME -- timestamp )
31     {
32         [ wYear>> ]
33         [ wMonth>> ]
34         [ wDay>> ]
35         [ wHour>> ]
36         [ wMinute>> ]
37         [ [ wSecond>> ] [ wMilliseconds>> 1000 /f ] bi + ]
38     } cleave gmt-offset-duration <timestamp> ;