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