]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/calendar/windows/windows.factor
factor: trim using lists
[factor.git] / basis / calendar / windows / windows.factor
index abec2dcf9fd59a995e3f7d540805f40ada459cd3..d17e1efbf1b0684b763f27b90fa4efd1b442964e 100644 (file)
@@ -1,17 +1,7 @@
-USING: calendar namespaces alien.c-types system
-windows.kernel32 kernel math combinators windows.errors
-accessors classes.struct calendar.format math.functions ;
+USING: accessors calendar combinators kernel math math.functions
+system windows.errors windows.kernel32 ;
 IN: calendar.windows
 
-M: windows gmt-offset ( -- hours minutes seconds )
-    TIME_ZONE_INFORMATION <struct>
-    dup GetTimeZoneInformation {
-        { TIME_ZONE_ID_INVALID [ win32-error-string throw ] }
-        { TIME_ZONE_ID_UNKNOWN [ Bias>> ] }
-        { TIME_ZONE_ID_STANDARD [ Bias>> ] }
-        { TIME_ZONE_ID_DAYLIGHT [ [ Bias>> ] [ DaylightBias>> ] bi + ] }
-    } case neg 60 /mod 0 ;
-
 : timestamp>SYSTEMTIME ( timestamp -- SYSTEMTIME )
     {
         [ year>> ]
@@ -25,7 +15,7 @@ M: windows gmt-offset ( -- hours minutes seconds )
             [ nip >integer ]
             [ - 1000 * >integer ] 2bi
         ]
-    } cleave \ SYSTEMTIME <struct-boa> ;
+    } cleave \ SYSTEMTIME boa ;
 
 : SYSTEMTIME>timestamp ( SYSTEMTIME -- timestamp )
     {
@@ -34,5 +24,17 @@ M: windows gmt-offset ( -- hours minutes seconds )
         [ wDay>> ]
         [ wHour>> ]
         [ wMinute>> ]
-        [ [ wSecond>> ] [ wMilliseconds>> 1000 /f ] bi + ]
-    } cleave gmt-offset-duration <timestamp> ;
+        [ [ wSecond>> ] [ wMilliseconds>> 1000 / ] bi + ]
+    } cleave instant <timestamp> ;
+
+M: windows gmt-offset
+    TIME_ZONE_INFORMATION new
+    dup GetTimeZoneInformation {
+        { TIME_ZONE_ID_INVALID [ win32-error ] }
+        { TIME_ZONE_ID_UNKNOWN [ Bias>> ] }
+        { TIME_ZONE_ID_STANDARD [ Bias>> ] }
+        { TIME_ZONE_ID_DAYLIGHT [ [ Bias>> ] [ DaylightBias>> ] bi + ] }
+    } case neg 60 /mod 0 ;
+
+M: windows now-gmt
+    SYSTEMTIME new [ GetSystemTime ] keep SYSTEMTIME>timestamp ;