lib/realtime: Add Timespec::to_f (and to_s) so one can print them easyly
authorJean Privat <jean@pryen.org>
Tue, 5 Aug 2014 02:27:15 +0000 (22:27 -0400)
committerJean Privat <jean@pryen.org>
Tue, 5 Aug 2014 02:27:15 +0000 (22:27 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/realtime.nit

index fd0fe86..38a601c 100644 (file)
@@ -60,6 +60,12 @@ extern class Timespec `{struct timespec*`}
        fun destroy `{
                free( recv );
        `}
+
+       # Seconds in Float
+       # Loss of precision but great to print
+       fun to_f: Float do return sec.to_f + nanosec.to_f / 1000000000.0
+
+       redef fun to_s do return "{to_f}s"
 end
 
 # Keeps track of real time