#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Wed, 09 May 2018 14:19:22 +0200
changeset 22828 1a4cf44b1ada
parent 22827 9ea9757226e5
child 22829 f8f21ccd46d5
#FEATURE by cg class: AbstractOperatingSystem class added: #getOSTimeWithNanos
AbstractOperatingSystem.st
--- a/AbstractOperatingSystem.st	Wed May 09 12:20:01 2018 +0200
+++ b/AbstractOperatingSystem.st	Wed May 09 14:19:22 2018 +0200
@@ -1140,7 +1140,6 @@
     "Created: / 12.11.1998 / 14:39:20 / cg"
 ! !
 
-
 !AbstractOperatingSystem class methodsFor:'executing OS commands-public'!
 
 executeCommand:aCommandString
@@ -6908,6 +6907,32 @@
     "
 !
 
+getOSTimeWithNanos
+    "This returns the OS time as a 2-element vector with milliseconds (as before)
+     plus nanoseconds.
+     The base of the returned value is not consistent across
+     different OS's - some return the number of microseconds since jan, 1st 1970;
+     others since 1900. The Time classes are prepared for this, and
+     converts as appropriate (by using my fromOSTime: conversion methods).
+
+     Don't use this method in application code since it is an internal (private)
+     interface. 
+     For compatibility use instances of Time, Date or Timestamp to work with."
+
+    "here, a fallback, which only provides a lower (typically: millisecond) resolution"
+
+    |osTime|
+
+    osTime := self getOSTimeWithMicros.
+    ^ { osTime first . (osTime second*1000) }
+
+    "
+     OperatingSystem getOSTime              1525868295396
+     OperatingSystem getOSTimeWithMicros    -> #(1525868292534 220) 
+     OperatingSystem getOSTimeWithNanos     -> #(1525868325652 456000)
+    "
+!
+
 getRealNanosecondTime
     "This returns the microsecond timers value - if available.
      On some machines, times with this precision may not be available,