lib/core: extend is_numeric to support negatives (!) and e notation
[nit.git] / lib / core / time.nit
index adac6ff..5fc37f2 100644 (file)
@@ -21,10 +21,8 @@ in "C Header" `{
        #include <time.h>
 `}
 
-redef class Object
-       # Unix time: the number of seconds elapsed since January 1, 1970
-       protected fun get_time: Int `{ return time(NULL); `}
-end
+# Unix time: the number of seconds elapsed since January 1, 1970
+fun get_time: Int `{ return time(NULL); `}
 
 redef class Sys
        # Wait a specific number of second and nanoseconds
@@ -34,6 +32,16 @@ redef class Sys
        `}
 end
 
+redef class Float
+       # Sleep approximately `self` seconds
+       fun sleep `{
+               time_t s = self;
+               long ns = (self-s) * 1000000000.0;
+               const struct timespec req = {s, ns};
+               nanosleep(&req, NULL);
+       `}
+end
+
 # Time since epoch
 extern class TimeT `{time_t`}