Timestamp.st
changeset 1501 2589005c849d
parent 1306 c0189edbd96c
child 1513 a4b4c4ce039c
--- a/Timestamp.st	Mon Jul 01 15:31:33 1996 +0200
+++ b/Timestamp.st	Mon Jul 01 15:33:58 1996 +0200
@@ -17,7 +17,7 @@
 	category:'Magnitude-General'
 !
 
-!AbsoluteTime class methodsFor:'documentation'!
+!AbsoluteTime  class methodsFor:'documentation'!
 
 copyright
 "
@@ -35,26 +35,29 @@
 
 documentation
 "
-    This class represents time values in seconds from 1st. Jan 1970, as
-    used in the Unix operating system. Its implementation is not the same
-    as in ST-80 (which represents Time as seconds from 1. Jan 1901.
+    This class represents absolute time values in millisSeconds starting some
+    time in the past. 
+    (typically, from 1st. Jan 1970, as used in the Unix operating system,
+     but other systems may bias the time differently.
+     Actually, the implementation does not depend or even know which time/date 
+     the OperatingSystem bases its time upon - it is simply keeping the value(s)
+     as return from the OS.
+     For conversion, these values are given back to the OS, which will know
+     how to convert these times.
+     This has the advantage, that time-stamps on files (such as last-access-
+     time or last-modifiaction-time) can be handled transparent to other
+     times - especially comparisons).
 
-    Actually, the implementation does not depend or even know which time/date 
-    the OperatingSystem bases its time upon - it is simply keeping the value(s)
-    as return from the OS.
-    For conversion, these values are given back to the OS, which will know
-    how to convert these times.
-    This has the advantage, that time-stamps on files (such as last-access-
-    time or last-modifiaction-time) can be handled transparent to other
-    times (especially comparison).
+    You should not interpret the osTime instance variable directly, instead
+    (if at all), as the OS to convert.
 
-    Since unix-times are 32 bit which does not fit into a SmallInteger, 
-    we keep low and hi 16bits of the time separately (it could have been 
-    implemented using LargeIntegers though).
+    Its implementation is not the same as in ST-80 
+    (which represents Time as seconds from 1. Jan 1901.
 
     This class should not be confused with Time (which only represents the
-    time within one day). Time instances cannot be used to compare times across
-    midnight; instances of AbsoluteTime can.
+    time within one day). 
+    Time instances cannot be used to compare times across midnight; 
+    instances of AbsoluteTime can.
 
     [author:]
         Claus Gittinger
@@ -65,24 +68,43 @@
 "
 ! !
 
-!AbsoluteTime class methodsFor:'instance creation'!
+!AbsoluteTime  class methodsFor:'instance creation'!
 
 day:d month:m year:y hour:h minutes:min seconds:s
     "return an instance of the receiver, given individual components.
      See also `AbsoluteTime now' and other protocol inherited
      from my superclass."
 
+    ^ self 
+        day:d month:m year:y hour:h 
+        minutes:min seconds:s milliseconds:0
+
+    "
+     AbsoluteTime day:2 month:1 year:1991 hour:12 minutes:30 seconds:0 
+     AbsoluteTime day:8 month:1 year:1995 hour:0 minutes:43 seconds:48 
+    "
+
+    "Modified: 1.7.1996 / 15:22:26 / cg"
+!
+
+day:d month:m year:y hour:h minutes:min seconds:s milliseconds:millis
+    "return an instance of the receiver, given individual components.
+     See also `AbsoluteTime now' and other protocol inherited
+     from my superclass."
+
     ^ self basicNew 
         fromOSTime:(OperatingSystem 
-                        computeTimePartsFromYear:y month:m day:d 
-                                            hour:h minute:min seconds:s)
+                        computeOSTimeFromYear:y month:m day:d 
+                                         hour:h minute:min seconds:s
+                                       millis:millis)
 
     "
      AbsoluteTime day:2 month:1 year:1991 hour:12 minutes:30 seconds:0 
-     AbsoluteTime day:8 month:1 year:1995 hour:0 minutes:43 seconds:48 
+     AbsoluteTime day:2 month:1 year:1991 hour:12 minutes:30 seconds:0 milliseconds:100
     "
 
-    "Modified: 19.4.1996 / 15:21:12 / cg"
+    "Created: 1.7.1996 / 14:46:09 / cg"
+    "Modified: 1.7.1996 / 15:22:07 / cg"
 !
 
 fromDate:aDate andTime:aTime
@@ -115,7 +137,7 @@
      Notice, that this is not the storeString format and 
      is different from the format expected by readFrom:."
 
-    |str day month year hour min sec ex|
+    |str day month year hour min sec millis ex|
 
     str := aStringOrStream readStream.
 
@@ -142,18 +164,26 @@
     sec := Integer readFrom:str onError:ex.
     (sec between:0 and:59) ifFalse:[^ exceptionBlock value].
 
+    str peek = '.' ifTrue:[
+        str next.
+        millis := Integer readFrom:str onError:ex.
+    ] ifFalse:[
+        millis := 0.
+    ].
+
     "special check"
     hour == 24 ifTrue:[
-	(min ~~ 0 or:[sec ~~ 0]) ifTrue:[^ exceptionBlock value].
+        (min ~~ 0 or:[sec ~~ 0]) ifTrue:[^ exceptionBlock value].
     ].
 
     ^ self day:day month:month year:year hour:hour minutes:min seconds:sec
 
     "
      AbsoluteTime readFrom:'20-2-1995 13:11:06'    
+     AbsoluteTime readFrom:'20-2-1995 13:11:06.100'    
     "
 
-    "Modified: 16.11.1995 / 22:49:39 / cg"
+    "Modified: 1.7.1996 / 14:44:09 / cg"
 ! !
 
 !AbsoluteTime methodsFor:'accessing'!
@@ -165,13 +195,25 @@
     |d|
 
     OperatingSystem computeDatePartsOf:osTime for:[:year :month :day |
-	d := day
+        d := day
     ].
     ^ d
 
     "
      AbsoluteTime now day 
     "
+
+    "Modified: 1.7.1996 / 15:23:02 / cg"
+!
+
+hour
+    "return the hour (0..23).
+     ST-80 Timestamp compatibility (I'd prefer the name #hours, for Time compatibility)."
+
+    ^ self hours
+
+    "Created: 1.7.1996 / 15:14:50 / cg"
+    "Modified: 1.7.1996 / 15:15:32 / cg"
 !
 
 hours
@@ -180,7 +222,7 @@
     |hr|
 
     OperatingSystem computeTimePartsOf:osTime for:[:hours :minutes :secs |
-	hr := hours
+        hr := hours
     ].
     ^ hr
 
@@ -188,6 +230,40 @@
      AbsoluteTime now hours 
     "
 
+    "Modified: 1.7.1996 / 15:20:51 / cg"
+!
+
+millisecond
+    "return the millisecond (0..999).
+     ST-80 Timestamp compatibility (I'd prefer the name #milliseconds)."
+
+    ^ self milliseconds
+
+    "Created: 1.7.1996 / 15:14:50 / cg"
+    "Modified: 1.7.1996 / 15:15:24 / cg"
+!
+
+milliseconds
+    "return the milliseconds (0..999)"
+
+    ^ osTime \\ 1000
+
+    "
+     AbsoluteTime now milliseconds 
+    "
+
+    "Modified: 1.7.1996 / 15:11:20 / cg"
+    "Created: 1.7.1996 / 15:15:02 / cg"
+!
+
+minute
+    "return the minute (0..59).
+     ST-80 Timestamp compatibility (I'd prefer the name #minutes, for Time compatibility)."
+
+    ^ self minutes
+
+    "Created: 1.7.1996 / 15:14:29 / cg"
+    "Modified: 1.7.1996 / 15:15:37 / cg"
 !
 
 minutes
@@ -196,7 +272,7 @@
     |m|
 
     OperatingSystem computeTimePartsOf:osTime for:[:hours :minutes :secs |
-	m := minutes
+        m := minutes
     ].
     ^ m
 
@@ -204,6 +280,7 @@
      AbsoluteTime now minutes 
     "
 
+    "Modified: 1.7.1996 / 15:20:53 / cg"
 !
 
 month
@@ -213,13 +290,25 @@
     |m|
 
     OperatingSystem computeDatePartsOf:osTime for:[ :year :month :day |
-	m := month
+        m := month
     ].
     ^ m
 
     "
      AbsoluteTime now month
     "
+
+    "Modified: 1.7.1996 / 15:23:05 / cg"
+!
+
+second
+    "return the second (0..59).
+     ST-80 Timestamp compatibility (I'd prefer the name #seconds, for Time compatibility)."
+
+    ^ self seconds
+
+    "Created: 1.7.1996 / 15:14:19 / cg"
+    "Modified: 1.7.1996 / 15:15:49 / cg"
 !
 
 seconds
@@ -228,7 +317,7 @@
     |s|
 
     OperatingSystem computeTimePartsOf:osTime for:[:hours :minutes :secs |
-	s := secs
+        s := secs
     ].
     ^ s
 
@@ -236,6 +325,7 @@
      AbsoluteTime now seconds 
     "
 
+    "Modified: 1.7.1996 / 15:21:02 / cg"
 !
 
 utcOffset
@@ -252,6 +342,7 @@
     "
 
     "Modified: 20.12.1995 / 17:28:49 / stefan"
+    "Modified: 1.7.1996 / 15:21:29 / cg"
 !
 
 year
@@ -261,13 +352,15 @@
     |y|
 
     OperatingSystem computeDatePartsOf:osTime for:[:year :month :day |
-	y := year
+        y := year
     ].
     ^ y
 
     "
      AbsoluteTime now year
     "
+
+    "Modified: 1.7.1996 / 15:23:08 / cg"
 ! !
 
 !AbsoluteTime methodsFor:'arithmetic'!
@@ -330,13 +423,9 @@
 > aTime
     "return true if the argument, aTime is after the receiver"
 
-    |myHi otherHi|
+    ^ self getMilliseconds > aTime getMilliseconds
 
-    myHi := self secondsHi. 
-    otherHi := aTime secondsHi.
-    myHi > otherHi ifTrue:[^ true].
-    myHi < otherHi ifTrue:[^ false].
-    ^ self secondsLow > aTime secondsLow
+    "Modified: 1.7.1996 / 15:24:38 / cg"
 !
 
 hash
@@ -405,13 +494,13 @@
     "append a user readable representation of the receiver to aStream.
      The format is compatible with readFromString:, but not with readFrom:."
 
-    |h min s d m y|
+    |h min s mil d m y|
 
     OperatingSystem computeDatePartsOf:osTime for:[
-	:year :month :day | d := day. m := month. y := year.
+        :year :month :day | d := day. m := month. y := year.
     ].
     OperatingSystem computeTimePartsOf:osTime for:[
-	:hours :minutes :secs | h := hours. min := minutes. s := secs.
+        :hours :minutes :secs :millis | h := hours. min := minutes. s := secs. mil := millis
     ].
     d printOn:aStream.
     aStream nextPut:$-.
@@ -424,13 +513,25 @@
     min printOn:aStream leftPaddedTo:2 with:$0.
     aStream nextPut:$:.
     s printOn:aStream leftPaddedTo:2 with:$0.
+    mil ~~ 0 ifTrue:[
+        aStream nextPut:$..
+        mil printOn:aStream leftPaddedTo:3 with:$0.
+    ].
 
     "
      AbsoluteTime now printOn:Transcript. Transcript cr. 
      (AbsoluteTime fromSeconds:0) printOn:Transcript. Transcript cr.
      Time now printOn:Transcript. Transcript cr.           
      Date today printOn:Transcript. Transcript cr.        
+
+     Time now asAbsoluteTime printOn:Transcript. Transcript cr.           
+     AbsoluteTime now printOn:Transcript. Transcript cr. 
+
+     Date today asAbsoluteTime printOn:Transcript. Transcript cr.           
+     Date today printOn:Transcript. Transcript cr.           
     "
+
+    "Modified: 1.7.1996 / 15:20:59 / cg"
 !
 
 storeOn:aStream
@@ -452,16 +553,28 @@
 
 !AbsoluteTime methodsFor:'private'!
 
-fromOSTimeLow:secsLow and:secsHi
+fromOSTime:anUninterpretedOSTime
     "strictly private: set the seconds from an OS time (since whatever)"
 
-    osTime := Array with:secsLow with:secsHi
+    osTime := anUninterpretedOSTime
+
+    "Created: 1.7.1996 / 14:33:21 / cg"
+!
+
+getMilliseconds
+    "strictly private: return the milliseconds (since whatever)"
+
+    ^ osTime
+
+    "Created: 1.7.1996 / 14:33:56 / cg"
 !
 
 getSeconds
     "strictly private: return the seconds (since whatever)"
 
-    ^ ((osTime at:2) * 16r10000) + (osTime at:1)
+    ^ osTime // 1000
+
+    "Modified: 1.7.1996 / 14:33:44 / cg"
 !
 
 secondsHi
@@ -476,12 +589,22 @@
     ^ osTime at:1
 !
 
+setMilliseconds:millis
+    "strictly private: set the milliseconds (since whatever)"
+
+    osTime := millis.
+
+    "Modified: 20.12.1995 / 11:46:36 / stefan"
+    "Created: 1.7.1996 / 14:34:24 / cg"
+!
+
 setSeconds:secs
     "strictly private: set the seconds (since whatever)"
 
-    osTime := Array with:(secs \\ 16r10000) with:(secs // 16r10000)
+    osTime := secs * 1000.
 
     "Modified: 20.12.1995 / 11:46:36 / stefan"
+    "Modified: 1.7.1996 / 14:34:10 / cg"
 !
 
 setSecondsLow:secsLow and:secsHi
@@ -490,8 +613,8 @@
     osTime := Array with:secsLow with:secsHi
 ! !
 
-!AbsoluteTime class methodsFor:'documentation'!
+!AbsoluteTime  class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.24 1996-04-26 14:12:46 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.25 1996-07-01 13:33:58 cg Exp $'
 ! !