--- a/AbstractTime.st Thu May 10 21:26:56 2018 +0200
+++ b/AbstractTime.st Thu May 10 23:54:49 2018 +0200
@@ -852,7 +852,9 @@
"return a new instance of myself, numberOfMilliSeconds afterwards."
^ self speciesNew
- setMilliseconds:(self getMilliseconds + numberOfMilliSeconds)
+ setMilliseconds:(self getMilliseconds + (numberOfMilliSeconds // 1))
+ additionalPicoseconds:(self additionalPicoseconds
+ + ((numberOfMilliSeconds \\ 1)*1000*1000*1000) rounded)
"
|t|
@@ -896,8 +898,7 @@
addSeconds:numberOfSeconds
"return a new instance of myself, numberOfSeconds afterwards."
- ^ self speciesNew
- setMilliseconds:(self getMilliseconds + (numberOfSeconds * 1000))
+ ^ self addMilliseconds:(numberOfSeconds * 1000)
"
|t|
@@ -1011,8 +1012,7 @@
subtractMilliseconds:numberOfMilliSeconds
"return a new instance of myself, numberOfMilliSeconds before."
- ^ self speciesNew
- setMilliseconds:(self getMilliseconds - numberOfMilliSeconds)
+ ^ self addMilliseconds:numberOfMilliSeconds negated
"
|t|
@@ -1056,8 +1056,7 @@
subtractSeconds:numberOfSeconds
"return a new instance of myself, numberOfSeconds before."
- ^ self speciesNew
- setMilliseconds:(self getMilliseconds - (numberOfSeconds * 1000))
+ ^ self addMilliseconds:(numberOfSeconds * -1000)
"
|t|
@@ -1105,20 +1104,143 @@
!AbstractTime methodsFor:'comparing'!
-< aTime
+< aTimeOrTimeDurationOrNumberOfSeconds
"return true if the receiver is before the argument"
- ^ self getMilliseconds < aTime getMilliseconds
+ |myMilliseconds otherMilliseconds myPicos otherPicos|
+
+ myMilliseconds := self getMilliseconds.
+ myPicos := self additionalPicoseconds.
+
+ aTimeOrTimeDurationOrNumberOfSeconds isNumber ifTrue:[
+ "backward compatibility for old code, which expects (time1 - time2) to return seconds"
+ otherMilliseconds := (aTimeOrTimeDurationOrNumberOfSeconds * 1000) asInteger. "integer seconds"
+ otherPicos := 0.
+ ] ifFalse:[
+ otherMilliseconds := aTimeOrTimeDurationOrNumberOfSeconds getMilliseconds.
+ otherPicos := aTimeOrTimeDurationOrNumberOfSeconds additionalPicoseconds.
+ ].
+ ^ (myMilliseconds < otherMilliseconds)
+ or:[ myMilliseconds = otherMilliseconds and:[myPicos < otherPicos ]].
+
+ "
+ (Timestamp now + 10) - Timestamp now < 10
+ (Timestamp now + 10) - Timestamp now < 11
+ "
+!
- "Modified: 3.7.1996 / 13:10:17 / cg"
+<= aTimeOrTimeDurationOrNumberOfSeconds
+ "return true if the receiver is before or the same time as the argument"
+
+ |myMilliseconds otherMilliseconds myPicos otherPicos|
+
+ myMilliseconds := self getMilliseconds.
+ myPicos := self additionalPicoseconds.
+
+ aTimeOrTimeDurationOrNumberOfSeconds isNumber ifTrue:[
+ "backward compatibility for old code, which expects (time1 - time2) to return seconds"
+ otherMilliseconds := (aTimeOrTimeDurationOrNumberOfSeconds * 1000) asInteger. "integer seconds"
+ otherPicos := 0.
+ ] ifFalse:[
+ otherMilliseconds := aTimeOrTimeDurationOrNumberOfSeconds getMilliseconds.
+ otherPicos := aTimeOrTimeDurationOrNumberOfSeconds additionalPicoseconds.
+ ].
+ ^ (myMilliseconds < otherMilliseconds)
+ or:[ myMilliseconds = otherMilliseconds and:[myPicos <= otherPicos ]].
+
+ "
+ (Timestamp now + 10) - Timestamp now <= 10
+ (Timestamp now + 10) - Timestamp now <= 11
+ (Timestamp now + 10) - Timestamp now <= 9
+ "
!
-> aTime
+= aTimeOrTimeDurationOrNumberOfSeconds
+ "return true if the receiver is before or the same time as the argument"
+
+ |myMilliseconds otherMilliseconds myPicos otherPicos|
+
+ myMilliseconds := self getMilliseconds.
+ myPicos := self additionalPicoseconds.
+
+ aTimeOrTimeDurationOrNumberOfSeconds isNumber ifTrue:[
+ "backward compatibility for old code, which expects (time1 - time2) to return seconds"
+ otherMilliseconds := (aTimeOrTimeDurationOrNumberOfSeconds * 1000) asInteger. "integer seconds"
+ otherPicos := 0.
+ ] ifFalse:[
+ otherMilliseconds := aTimeOrTimeDurationOrNumberOfSeconds getMilliseconds.
+ otherPicos := aTimeOrTimeDurationOrNumberOfSeconds additionalPicoseconds.
+ ].
+ ^ (myMilliseconds = otherMilliseconds) and:[myPicos = otherPicos ].
+
+ "
+ (Timestamp now + 10) - Timestamp now = 10
+ (Timestamp now + 10) - Timestamp now = 9
+
+ (Time now + 10 seconds) - Time now = 10
+ (Time now + 10) - Time now = 10
+
+ (Time now + 10 seconds) > Time now
+ (Time now + 10) > Time now
+
+ (Time now + 10 milliSeconds) > Time now
+ (Time now + 0 milliseconds) > Time now
+ "
+!
+
+> aTimeOrTimeDurationOrNumberOfSeconds
"return true if the receiver is after the argument"
- ^ self getMilliseconds > aTime getMilliseconds
+ |myMilliseconds otherMilliseconds myPicos otherPicos|
+
+ myMilliseconds := self getMilliseconds.
+ myPicos := self additionalPicoseconds.
+
+ aTimeOrTimeDurationOrNumberOfSeconds isNumber ifTrue:[
+ "backward compatibility for old code, which expects (time1 - time2) to return seconds"
+ otherMilliseconds := (aTimeOrTimeDurationOrNumberOfSeconds * 1000) asInteger. "integer seconds"
+ otherPicos := 0.
+ ] ifFalse:[
+ otherMilliseconds := aTimeOrTimeDurationOrNumberOfSeconds getMilliseconds.
+ otherPicos := aTimeOrTimeDurationOrNumberOfSeconds additionalPicoseconds.
+ ].
+ ^ (myMilliseconds > otherMilliseconds)
+ or:[ myMilliseconds = otherMilliseconds and:[myPicos > otherPicos ]].
+
+ "
+ (Timestamp now + 10) - Timestamp now > 10
+ (Timestamp now + 10) - Timestamp now > 9
+ "
+!
+
+>= aTimeOrTimeDurationOrNumberOfSeconds
+ "return true if the receiver is after the argument or the same"
- "Modified: 1.7.1996 / 15:24:38 / cg"
+ |myMilliseconds otherMilliseconds myPicos otherPicos|
+
+ myMilliseconds := self getMilliseconds.
+ myPicos := self additionalPicoseconds.
+
+ aTimeOrTimeDurationOrNumberOfSeconds isNumber ifTrue:[
+ "backward compatibility for old code, which expects (time1 - time2) to return seconds"
+ otherMilliseconds := (aTimeOrTimeDurationOrNumberOfSeconds * 1000) asInteger. "integer seconds"
+ otherPicos := 0.
+ ] ifFalse:[
+ otherMilliseconds := aTimeOrTimeDurationOrNumberOfSeconds getMilliseconds.
+ otherPicos := aTimeOrTimeDurationOrNumberOfSeconds additionalPicoseconds.
+ ].
+ ^ (myMilliseconds > otherMilliseconds)
+ or:[ myMilliseconds = otherMilliseconds and:[myPicos >= otherPicos ]].
+
+ "
+ (Timestamp now + 10) - Timestamp now >= 11
+ (Timestamp now + 10) - Timestamp now >= 10
+ (Timestamp now + 10) - Timestamp now >= 9
+ "
+!
+
+hash
+ ^ self getMilliseconds
! !
!AbstractTime methodsFor:'converting'!