'From Cuis 2.3 of 22 March 2010 [latest update: #472] on 12 April 2010 at 10:28:26 pm'!

!Timespan methodsFor: 'ansi protocol' stamp: 'jmv 4/12/2010 22:20'!
+ aDuration

	^self class classDefinesDuration
		ifTrue: [ self class including: start + aDuration ]
		ifFalse: [ self class starting: start + aDuration duration: duration ]! !

!Timespan methodsFor: 'ansi protocol' stamp: 'jmv 4/12/2010 22:20'!
- aDuration

	^self class classDefinesDuration
		ifTrue: [ self class including: start - aDuration ]
		ifFalse: [ self class starting: start - aDuration duration: duration ]! !

!Timespan methodsFor: 'squeak protocol' stamp: 'jmv 4/12/2010 22:21'!
intersection: aTimespan

	 "Return the Timespan both have in common, or nil"

	 | aBegin anEnd |
	 aBegin _ self start max: aTimespan start.
	 anEnd _ self end min: aTimespan end.
	 anEnd < aBegin ifTrue: [^nil].

	 ^ Timespan starting: aBegin ending: anEnd! !

!Timespan methodsFor: 'squeak protocol' stamp: 'jmv 4/12/2010 22:26'!
union: aTimespan
	 "Return the Timespan spanned by both"
	"
	| union timespan |
	timespan := Timespan starting:
					(DateAndTime year: 2003 month: 03 day: 22 hour: 12 minute: 0 second: 0)
						duration: (Duration hours: 100).
	union := timespan union: timespan.
	
	self 
		assert: (union start = timespan start);
		assert: (union duration = timespan duration)
	"

	| aBegin anEnd |

	aBegin _ self start min: aTimespan start.
	anEnd _ self end max: aTimespan end.
	^ Timespan starting: aBegin ending: anEnd + DateAndTime clockPrecision! !

