]> gitweb.factorcode.org Git - factor.git/commitdiff
add timespec>timestamp word
authorDoug Coleman <doug.coleman@gmail.com>
Mon, 6 Oct 2008 22:17:49 +0000 (17:17 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Mon, 6 Oct 2008 22:17:49 +0000 (17:17 -0500)
basis/calendar/calendar.factor
basis/structs/structs.factor
basis/unix/time/time.factor

index 31c835aada6888869567eb865a89e272d5a9a11c..8a27a46aa202f0041c428f1a9d3939bd9fef81f1 100644 (file)
@@ -402,9 +402,16 @@ PRIVATE>
 : time-since-midnight ( timestamp -- duration )
     dup midnight time- ;
 
+: since-1970 ( time -- timestamp )
+    unix-1970 time+ >local-time ;
+
 : timeval>unix-time ( timeval -- timestamp )
     [ timeval-sec seconds ] [ timeval-usec microseconds ] bi
-    time+ unix-1970 time+ >local-time ;
+    time+ since-1970 ;
+
+: timespec>unix-time ( timeval -- timestamp )
+    [ timespec-sec seconds ] [ timespec-nsec nanoseconds ] bi
+    time+ since-1970 ;
 
 M: timestamp sleep-until timestamp>millis sleep-until ;
 
index f54917dc472938a53d17d5f50c96b952d3a03ec6..51ac517af31b365b09e551dd7e4940f8dc978a6a 100644 (file)
@@ -10,3 +10,13 @@ C-STRUCT: timeval
     "timeval" <c-object>
     [ set-timeval-usec ] keep
     [ set-timeval-sec ] keep ;
+
+C-STRUCT: timespec
+    { "time_t" "sec" }
+    { "long" "nsec" } ;
+
+: make-timespec ( ms -- timespec )
+    1000 /mod 1000000 *
+    "timespec" <c-object>
+    [ set-timespec-nsec ] keep
+    [ set-timespec-sec ] keep ;
index 4fbb20dca05456851ea3bbab247a2fda9abc1c98..26b42ddfe7e75d6022d590d4befba26dc3997096 100644 (file)
@@ -1,6 +1,4 @@
-
 USING: kernel alien.syntax alien.c-types math ;
-
 IN: unix.time
 
 TYPEDEF: uint time_t
@@ -18,16 +16,6 @@ C-STRUCT: tm
     { "long" "gmtoff" } ! Seconds: 0-59 (K&R says 0-61?)
     { "char*" "zone" } ;
 
-C-STRUCT: timespec
-    { "time_t" "sec" }
-    { "long" "nsec" } ;
-
-: make-timespec ( ms -- timespec )
-    1000 /mod 1000000 *
-    "timespec" <c-object>
-    [ set-timespec-nsec ] keep
-    [ set-timespec-sec ] keep ;
-
 FUNCTION: time_t time ( time_t* t ) ;
 FUNCTION: tm* localtime ( time_t* clock ) ;
 FUNCTION: int gettimeofday ( timespec* TP, void* TZP ) ;