]> gitweb.factorcode.org Git - factor.git/commitdiff
Add words for working with CFTimeInterval and CFAbsoluteDate types
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sat, 13 Dec 2008 03:06:46 +0000 (21:06 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sat, 13 Dec 2008 03:06:46 +0000 (21:06 -0600)
basis/core-foundation/core-foundation.factor
basis/core-foundation/timers/timers.factor

index 0f64c0666f4eaa188a9b165132d503a07f03bee3..51173aff211019b4c5009c3085930bf7b97f10c5 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2006, 2008 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.syntax destructors accessors kernel ;
+USING: alien.syntax destructors accessors kernel calendar ;
 IN: core-foundation
 
 TYPEDEF: void* CFTypeRef
@@ -30,3 +30,10 @@ M: CFRelease-destructor dispose* alien>> CFRelease ;
 
 : |CFRelease ( alien -- alien )
     dup f CFRelease-destructor boa |dispose drop ; inline
+
+: >CFTimeInterval ( duration -- interval )
+    duration>seconds ; inline
+
+: >CFAbsoluteTime ( timestamp -- time )
+    T{ timestamp { year 2001 } { month 1 } { day 1 } } time-
+    duration>seconds ; inline
index 049e80b20f29c505581afe74fa1cb3ec39dcc959..0acd92ced1c93cda046ef39820ee2640691e8741 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.syntax system math kernel core-foundation ;
+USING: alien.syntax system math kernel core-foundation calendar ;
 IN: core-foundation.timers
 
 TYPEDEF: void* CFRunLoopTimerRef
@@ -18,12 +18,16 @@ FUNCTION: CFRunLoopTimerRef CFRunLoopTimerCreate (
 ) ;
 
 : <CFTimer> ( callback -- timer )
-    [ f millis 1000 /f 60 0 0 ] dip f CFRunLoopTimerCreate ;
+    [ f now >CFAbsoluteTime 60 0 0 ] dip f CFRunLoopTimerCreate ;
 
 FUNCTION: void CFRunLoopTimerInvalidate (
    CFRunLoopTimerRef timer
 ) ;
 
+FUNCTION: Boolean CFRunLoopTimerIsValid (
+   CFRunLoopTimerRef timer
+) ;
+
 FUNCTION: void CFRunLoopTimerSetNextFireDate (
    CFRunLoopTimerRef timer,
    CFAbsoluteTime fireDate