--- a/TimeDuration.st Mon Mar 18 11:55:48 2002 +0100
+++ b/TimeDuration.st Mon Mar 18 12:01:22 2002 +0100
@@ -37,38 +37,24 @@
documentation
"
- Instances of time represent a particular time-of-day.
- Since they only store hours, minutes and seconds within a day,
- they cannot be used to compare times across midnight
- (i.e. they should not be used as timeStamps).
-
- Use instances of AbsoluteTime (and read the comment there) to do this.
-
- Examples:
- |t|
-
- t := Time now.
- Transcript showCR:t.
-
-
- |t1 t2|
-
- t1 := Time now.
- (Delay forSeconds:10) wait.
- t2 := Time now.
- t2 - t1
-
- [author:]
- Claus Gittinger
-
- [see also:]
- Date AbsoluteTime AbstractTime OperatingSystem
- Filename
"
! !
!TimeDuration class methodsFor:'instance creation'!
+fromSeconds:secondsInterval
+ "redefined to disable wrapping at 24hours."
+
+ ^ self new setSeconds:secondsInterval
+
+ "
+ Time hours:2 minutes:33 seconds:0
+ Time hours:100 minutes:33 seconds:0
+ TimeDuration hours:2 minutes:33 seconds:0 millis:123
+ TimeDuration hours:100 minutes:33 seconds:0 millis:123
+ "
+!
+
hours:h minutes:m seconds:s millis:millis
"return an instance of Time representing the given time.
See also Time now / Date today / AbsoluteTime now."
@@ -76,7 +62,8 @@
^ self basicNew setHours:h minutes:m seconds:s millis:millis
"
- TimeDuration hours:2 minutes:33 seconds:0 millis:123
+ TimeDuration hours:2 minutes:33 seconds:0 millis:123
+ TimeDuration hours:100 minutes:33 seconds:0 millis:123
"
! !
@@ -96,6 +83,10 @@
!TimeDuration methodsFor:'accessing'!
+days
+ ^ timeEncoding // 1000 // 3600 // 24
+!
+
milliseconds
^ timeEncoding \\ 1000
! !
@@ -108,6 +99,44 @@
^ Time hours:(self hours) minutes:(self minutes) seconds:(self seconds)
! !
+!TimeDuration methodsFor:'printing'!
+
+addPrintBindingsTo:aDictionary
+ "add bindings for printing to aDictionary."
+
+ |hoursInDay s|
+
+ super addPrintBindingsTo:aDictionary.
+ aDictionary at:$d put:self days.
+
+ hoursInDay := self hours \\ 24.
+ aDictionary at:#Hd put:(s := hoursInDay printString).
+ aDictionary at:#hd put:(s leftPaddedTo:2 with:$0).
+!
+
+printOn:aStream
+ "append a user printed representation of the receiver to aStream.
+ The format is suitable for a human - not meant to be read back."
+
+ |fmt|
+
+ self hours >= 24 ifTrue:[
+ fmt := '%dd %(Hd)h %Mm %S.%is'
+ ] ifFalse:[
+ fmt := '%Hh %Mm %S.%is'
+ ].
+ ^ self
+ printOn:aStream
+ format:fmt.
+
+ "
+ TimeDuration hours:2 minutes:33 seconds:0 millis:123
+ TimeDuration hours:100 minutes:33 seconds:0 millis:123
+ TimeDuration hours:10000 minutes:33 seconds:0 millis:123
+ TimeDuration hours:1000000 minutes:33 seconds:0 millis:123
+ "
+! !
+
!TimeDuration methodsFor:'private'!
getMilliseconds
@@ -125,7 +154,7 @@
setHours:h minutes:m seconds:s millis:millis
"set my time given individual values"
- self setMilliseconds:(((h\\24) * 60 * 60 ) + (m * 60) + s) * 1000 + millis.
+ self setMilliseconds:((h * 60 * 60 ) + (m * 60) + s) * 1000 + millis.
!
setMilliseconds:millis
@@ -143,5 +172,5 @@
!TimeDuration class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/Attic/TimeDuration.st,v 1.1 2001-11-08 16:03:35 md Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/Attic/TimeDuration.st,v 1.2 2002-03-18 11:01:22 cg Exp $'
! !