AbstractTime.st
changeset 240 f5ff68fffb92
child 275 a76029ddaa98
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AbstractTime.st	Wed Feb 08 04:10:51 1995 +0100
@@ -0,0 +1,169 @@
+"
+ COPYRIGHT (c) 1995 by Claus Gittinger
+	      All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+
+'From Smalltalk/X, Version:2.10.4 on 7-feb-1995 at 11:53:03 pm'!
+
+Magnitude subclass:#AbstractTime
+	 instanceVariableNames:''
+	 classVariableNames:''
+	 poolDictionaries:''
+	 category:'Magnitude-General'
+!
+
+!AbstractTime class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 1995 by Claus Gittinger
+	      All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+!
+
+documentation
+"
+    This is an abstract class; there are no instances in the system.
+    It is meant as a home for methods common to time handling clases.
+"
+!
+
+version
+"
+$Header: /cvs/stx/stx/libbasic/AbstractTime.st,v 1.1 1995-02-08 03:10:51 claus Exp $
+"
+! !
+
+!AbstractTime class methodsFor:'instance creation'!
+
+fromOSTime:osTime
+    "return a time, representing the time given by the operatingSystem time.
+     Not meant for public use."
+
+    ^ self basicNew fromOSTimeLow:(osTime at:1) and:(osTime at:2)
+!
+
+now
+    "return an instance of myself representing this moment"
+
+    ^ self fromOSTime:(OperatingSystem getTimeParts)
+
+    "
+     AbsoluteTime now   
+     Time now   
+    "
+!
+
+fromSeconds:seconds
+    "return an instance that is constructed from seconds.
+     This method is only allowed for second values as returned by
+     getSeconds, possibly adding/subtracting to that. Never
+     depend on any specific interpretation of the seconds."
+
+   ^ self basicNew setSeconds:seconds
+
+    "
+     Time fromSeconds:0
+     AbsoluteTime fromSeconds:0
+    "
+
+!
+
+fromOSTimeLow:osTimeLow and:osTimeHigh
+    "return a time, representing the time given by the operatingSystem time.
+     Not meant for public use."
+
+    ^ self basicNew fromOSTimeLow:osTimeLow and:osTimeHigh
+!
+
+dateAndTimeNow
+    "return an array filled with date and time"
+
+    ^ Array with:(Date today) with:(Time now)
+
+    "
+     Time dateAndTimeNow
+    "
+! !
+
+!AbstractTime class methodsFor:'obsolete'!
+
+fromUnixTimeLow:low and:hi
+    "return an instance of myself, given the unix time.
+     Internal interface - not for public use."
+
+    ^ self fromOSTimeLow:low and:hi
+! !
+
+!AbstractTime class methodsFor:'queries'!
+
+secondClock
+    "return seconds of now - for GNU-ST compatibility"
+
+    ^ OperatingSystem getTime
+
+    "
+     AbstractTime secondClock 
+    "
+!
+
+millisecondClockValue
+    "return the millisecond clock - since this one overruns
+     regularly, use the value only for short timing deltas.
+     Also remember that it wraps when compares these values."
+
+    ^ OperatingSystem getMillisecondTime.
+
+    "
+     Time millisecondClockValue 
+    "
+! !
+
+!AbstractTime class methodsFor:'timing evaluations'!
+
+secondsToRun:aBlock
+    "evaluate the argument, aBlock; return the number of seconds it took"
+
+    |startTime endTime|
+
+    startTime := self now.
+    aBlock value.
+    endTime := self now.
+    ^ endTime - startTime
+!
+
+millisecondsToRun:aBlock
+    "evaluate the argument, aBlock; return the number of milliseconds it took"
+
+    |startTime endTime|
+
+    startTime := self millisecondClockValue.
+    aBlock value.
+    endTime := self millisecondClockValue.
+    ^ endTime - startTime
+
+    "
+     Time millisecondsToRun:[100 factorial]  
+    "
+! !
+
+!AbstractTime class methodsFor:'ST-80 compatibility'!
+
+totalSeconds
+    ^ self secondClock
+! !
+