Merge: doc: fixed some typos and other misc. corrections
[nit.git] / lib / core / time.nit
index 999f1e9..e5248d9 100644 (file)
@@ -19,11 +19,28 @@ import stream
 
 in "C Header" `{
        #include <time.h>
+       #include <sys/time.h>
 `}
 
-# Unix time: the number of seconds elapsed since January 1, 1970
+# The number of seconds elapsed since January 1, 1970
+#
+# Uses the Unix function `time`.
 fun get_time: Int `{ return time(NULL); `}
 
+# The number of milliseconds elapsed since January 1, 1970
+#
+# Returns `get_microtime / 1000`
+fun get_millitime: Int do return get_microtime / 1000
+
+# The number of microseconds elapsed since January 1, 1970
+#
+# Uses the Unix function `gettimeofday`.
+fun get_microtime: Int `{
+       struct timeval val;
+       gettimeofday(&val, NULL);
+       return val.tv_sec * 1000000 + val.tv_usec;
+`}
+
 redef class Sys
        # Wait a specific number of second and nanoseconds
        #
@@ -34,6 +51,13 @@ redef class Sys
        `}
 end
 
+redef class Int
+       # Sleep approximately `self` seconds
+       #
+       # Is not interrupted by signals.
+       fun sleep do to_f.sleep
+end
+
 redef class Float
        # Sleep approximately `self` seconds
        #