#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Wed, 09 May 2018 16:17:01 +0200
changeset 22836 1c878b36a068
parent 22835 157b20cb8547
child 22837 c8ab3b3ad654
#FEATURE by cg class: AbstractTime some refactorings and many comments added: #additionalPicoseconds #fromOSTimeWithMilliseconds:additionalPicoseconds: #printStringIso8601 comment/format in: #asMilliseconds #getMilliseconds changed: #microseconds (send #additionalPicoseconds instead of #picoseconds) #picoseconds #printStringIso8601Format class: AbstractTime class comment/format in: #nowWithMicroseconds #utcNowWithMicroseconds #utcNowWithMilliseconds
AbstractTime.st
--- a/AbstractTime.st	Wed May 09 16:16:03 2018 +0200
+++ b/AbstractTime.st	Wed May 09 16:17:01 2018 +0200
@@ -262,12 +262,13 @@
     osTime := OperatingSystem getOSTimeWithMicros.
     millis := osTime at:1.
     micros := osTime at:2.
-    ^ self basicNew fromOSTimeWithMilliseconds:millis picoseconds:(micros*(1000*1000)).
+    ^ self basicNew fromOSTimeWithMilliseconds:millis additionalPicoseconds:(micros*(1000*1000)).
 
     "
      Timestamp now   
      Time now
      Timestamp nowWithMilliseconds
+     Timestamp nowWithMicroseconds
     "
 
     "Modified: 1.7.1996 / 15:20:10 / cg"
@@ -671,7 +672,7 @@
 microseconds
     "return the microseconds within the current second (0..999999)"
 
-    ^ (self milliseconds * 1000) + (self picoseconds // (1000*1000)).
+    ^ (self milliseconds * 1000) + (self additionalPicoseconds // (1000*1000)).
 
     "
      Timestamp now microseconds   
@@ -691,13 +692,17 @@
 !
 
 picoseconds
-    "return the additional picoseconds within the current second (0..999999999).
-     Here, assume that we have none"
+    "return the picoseconds within the current second (0..999999999).
+     notice: that is NOT the total number of picoseconds,
+     but the fractional part (within the second) only. 
+     Use this only for printing.
+     Here, fall back and generate something based on the milliseconds"
 
-    ^ 0.
+    ^ self milliseconds * 1000 * 1000 * 1000.
 
     "
      Timestamp now picoseconds
+     Timestamp nowWithMicroseconds picoseconds
     "
 !
 
@@ -1100,7 +1105,9 @@
 !
 
 asMilliseconds
-    "return the number of milliseconds elapsed since midnight"
+    "return the number of milliseconds elapsed since some starttime,
+     which is subclass specific (i.e. Time: since midnight; Timestamp: since the epoch).
+     Use this only to compute relative millisecond deltas."
 
     ^ self getMilliseconds
 
@@ -1592,12 +1599,12 @@
     "Modified: 22.2.1996 / 16:58:30 / cg"
 !
 
-printStringIso8601Format
+printStringIso8601
     "return the Iso8601 representation of the receiver with local timezon information.
      This format looks like:
-	1999-01-01T24:00:00
+        1999-01-01T24:00:00
      or, for zero hr:min:sec,
-	1999-01-01
+        1999-01-01
      Of course, a 24 hour clock is used."
 
     ^ String streamContents:[:s | self printIso8601FormatOn:s]
@@ -1605,10 +1612,39 @@
     "
      Timestamp now printStringIso8601Format
     "
+!
+
+printStringIso8601Format
+    <resource: #obsolete>
+
+    "return the Iso8601 representation of the receiver with local timezon information.
+     This format looks like:
+        1999-01-01T24:00:00
+     or, for zero hr:min:sec,
+        1999-01-01
+     Of course, a 24 hour clock is used."
+
+    self obsoleteMethodWarning:'use printStringIso8601'.
+    ^ self printStringIso8601
+
+    "
+     Timestamp now printStringIso8601Format
+    "
 ! !
 
 !AbstractTime methodsFor:'private'!
 
+additionalPicoseconds
+    "return the additional picoseconds within the current second (0..999999999).
+     Here, assume that we have none"
+
+    ^ 0.
+
+    "
+     Timestamp now picoseconds
+    "
+!
+
 fromOSTime:osTime
     "set my time, from operatingSystems time parts"
 
@@ -1623,6 +1659,12 @@
     self subclassResponsibility
 !
 
+fromOSTimeWithMilliseconds:anUninterpretedOSTime additionalPicoseconds:picos
+    "strictly private: set the milliseconds from an OS time (since the epoch) plus picoSeconds"
+
+    self subclassResponsibility
+!
+
 fromOSTimeWithMilliseconds:anUninterpretedOSTime picoseconds:picos
     "strictly private: set the milliseconds from an OS time (since the epoch) plus picoSeconds"
 
@@ -1632,7 +1674,10 @@
 getMilliseconds
     "get the milliseconds since some point of time in the past.
      Since I am abstract (not knowing how the time is actually
-     represented), this must be done by a concrete class."
+     represented), this must be done by a concrete class.
+     Also be aware that the returned value is concrete-class specific;
+     Time returns the millis since midnight, Timestamp since the epoch.
+     Use this only to compute relative time deltas."
 
     ^ self subclassResponsibility