[Pkg] The Trunk: Chronology-Tests-dtl.1.mcz

commits at source.squeak.org commits at source.squeak.org
Sat Feb 27 23:54:09 UTC 2016


David T. Lewis uploaded a new version of Chronology-Tests to project The Trunk:
http://source.squeak.org/trunk/Chronology-Tests-dtl.1.mcz

==================== Summary ====================

Name: Chronology-Tests-dtl.1
Author: dtl
Time: 27 February 2016, 6:38:08.308272 pm
UUID: c46456d5-c9fe-41ff-9bdb-3d4f7ea4be0b
Ancestors: 

Move Kernel-Chronology to Chronology-Core and KernelTests-Chronology to Chronology-Tests

==================== Snapshot ====================

SystemOrganization addCategory: #'Chronology-Tests'!

TestCase subclass: #DateAndTimeEpochTest
	instanceVariableNames: 'aDateAndTime aDuration aTimeZone localTimeZoneToRestore'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Chronology-Tests'!

!DateAndTimeEpochTest commentStamp: 'tlk 1/6/2004 18:27' prior: 0!
I represent one of several Sunit test Cases intentended to provide complete coverage  for the Chronology set of classes as part of the external testing. The other Chronology sunit test cases are:
 DateTestCase
 DateAndTimeLeapTestCase,
 DurationTestCase,
 ScheduleTestCase
 TimeStampTestCase
 TimespanDoTestCase, 
 TimespanDoSpanAYearTestCase, 
 TimespanTestCase, 
 YearMonthWeekTestCase.  
These tests attempt to exercise all public and private methods.  Except, they do not explicitly depreciated methods. tlk
My fixtures are:
aDateAndTime = January 01, 1901 midnight (the start of the Squeak epoch) with localTimeZone = Grenwhich Meridian (local offset = 0 hours)
aDuration = 1 day, 2 hours, 3, minutes, 4 seconds and 5 nano seconds.
aTimeZone =  'Epoch Test Time Zone', 'ETZ' , offset: 12 hours, 15 minutes. !

----- Method: DateAndTimeEpochTest>>setUp (in category 'running') -----
setUp
     localTimeZoneToRestore := DateAndTime localTimeZone.
	aDateAndTime :=  DateAndTime localTimeZone: TimeZone default; epoch.
	aTimeZone := TimeZone offset: (Duration minutes: 135) name: 'Epoch Test Time Zone' abbreviation: 'ETZ'.
	aDuration := Duration days: 1 hours: 2 minutes: 3 seconds: 4 nanoSeconds: 5 !

----- Method: DateAndTimeEpochTest>>tearDown (in category 'running') -----
tearDown
     DateAndTime localTimeZone: localTimeZoneToRestore.
     "wish I could remove the time zones I added earlier, tut there is no method for that"
!

----- Method: DateAndTimeEpochTest>>testAsDate (in category 'testing') -----
testAsDate
	self assert: aDateAndTime asDate =   'January 1, 1901' asDate.

!

----- Method: DateAndTimeEpochTest>>testAsDateAndTime (in category 'testing') -----
testAsDateAndTime
	self assert: aDateAndTime asDateAndTime =  aDateAndTime
	
!

----- Method: DateAndTimeEpochTest>>testAsDuration (in category 'testing') -----
testAsDuration
	self assert: aDateAndTime asDuration =  0 asDuration
	
!

----- Method: DateAndTimeEpochTest>>testAsLocal (in category 'testing') -----
testAsLocal
	self assert: aDateAndTime asLocal =  aDateAndTime.
	self assert: aDateAndTime asLocal = (aDateAndTime utcOffset: aDateAndTime class localOffset)
	
!

----- Method: DateAndTimeEpochTest>>testAsMonth (in category 'testing') -----
testAsMonth
	self assert: aDateAndTime asMonth = (Month month: 'January' year: 1901). 
!

----- Method: DateAndTimeEpochTest>>testAsNanoSeconds (in category 'testing') -----
testAsNanoSeconds
	self assert: aDateAndTime asNanoSeconds =  0 asDuration asNanoSeconds
	
!

----- Method: DateAndTimeEpochTest>>testAsSeconds (in category 'testing') -----
testAsSeconds
	self assert: aDateAndTime asSeconds =  0 asDuration asSeconds
	
!

----- Method: DateAndTimeEpochTest>>testAsTime (in category 'testing') -----
testAsTime
	self assert: aDateAndTime asTime =  Time midnight.
!

----- Method: DateAndTimeEpochTest>>testAsTimeStamp (in category 'testing') -----
testAsTimeStamp
	self assert: aDateAndTime asTimeStamp =  TimeStamp new.
!

----- Method: DateAndTimeEpochTest>>testAsUTC (in category 'testing') -----
testAsUTC
	self assert: aDateAndTime asUTC =  aDateAndTime
          !

----- Method: DateAndTimeEpochTest>>testAsWeek (in category 'testing') -----
testAsWeek
	self assert: aDateAndTime asWeek = (Week starting: '12-31-1900' asDate). 

!

----- Method: DateAndTimeEpochTest>>testAsYear (in category 'testing') -----
testAsYear
	self assert: aDateAndTime asYear =   (Year starting: '01-01-1901' asDate). 
!

----- Method: DateAndTimeEpochTest>>testCurrent (in category 'testing') -----
testCurrent
	self deny: aDateAndTime =  (DateAndTime current).
!

----- Method: DateAndTimeEpochTest>>testDateTime (in category 'testing') -----
testDateTime
	self assert: aDateAndTime =  (DateAndTime date: '01-01-1901' asDate time: '00:00:00' asTime)
!

----- Method: DateAndTimeEpochTest>>testDay (in category 'testing') -----
testDay
	self assert: aDateAndTime day =   DateAndTime new day
!

----- Method: DateAndTimeEpochTest>>testDayMonthYearDo (in category 'testing') -----
testDayMonthYearDo
	|iterations|
	iterations := 0.
	self assert: (aDateAndTime dayMonthYearDo: [:eachDay :eachMonth :eachYear |  iterations := iterations + 1])  = 1.
	self assert: (aDateAndTime dayMonthYearDo: [:eachDay :eachMonth :eachYear |  eachYear])  = 1901.
	self assert: (aDateAndTime dayMonthYearDo: [:eachDay :eachMonth :eachYear |  eachMonth]) = 1.
	self assert: (aDateAndTime dayMonthYearDo: [:eachDay :eachMonth :eachYear |  eachDay]) = 1.
!

----- Method: DateAndTimeEpochTest>>testDayOfMonth (in category 'testing') -----
testDayOfMonth
	self assert: aDateAndTime dayOfMonth  = 1.
!

----- Method: DateAndTimeEpochTest>>testDayOfWeek (in category 'testing') -----
testDayOfWeek
	self assert: aDateAndTime dayOfWeek  = 3.
	self assert: aDateAndTime dayOfWeekAbbreviation = 'Tue'.
	self assert: aDateAndTime dayOfWeekName = 'Tuesday'.
!

----- Method: DateAndTimeEpochTest>>testDayOfYear (in category 'testing') -----
testDayOfYear
	self assert: aDateAndTime dayOfYear  = 1.

!

----- Method: DateAndTimeEpochTest>>testDaysInMonth (in category 'testing') -----
testDaysInMonth
	self assert: aDateAndTime daysInMonth  = 31.

!

----- Method: DateAndTimeEpochTest>>testDaysInYear (in category 'testing') -----
testDaysInYear
	self assert: aDateAndTime daysInYear  = 365.

!

----- Method: DateAndTimeEpochTest>>testDaysLeftInYear (in category 'testing') -----
testDaysLeftInYear
	self assert: aDateAndTime daysLeftInYear  = 364.

!

----- Method: DateAndTimeEpochTest>>testDuration (in category 'testing') -----
testDuration
	self assert: aDateAndTime duration  = 0 asDuration.

!

----- Method: DateAndTimeEpochTest>>testEpoch (in category 'testing') -----
testEpoch
	self assert: aDateAndTime =  '1901-01-01T00:00:00+00:00' asDateAndTime
!

----- Method: DateAndTimeEpochTest>>testFirstDayOfMonth (in category 'testing') -----
testFirstDayOfMonth
	self assert: aDateAndTime firstDayOfMonth =   1
!

----- Method: DateAndTimeEpochTest>>testFromSeconds (in category 'testing') -----
testFromSeconds
	self assert: aDateAndTime =  (DateAndTime fromSeconds: 0).
!

----- Method: DateAndTimeEpochTest>>testFromString (in category 'testing') -----
testFromString
	self assert: aDateAndTime =  (DateAndTime fromString: ' 1901-01-01T00:00:00+00:00').
	self assert: aDateAndTime =  (DateAndTime fromString: ' 1901-01-01T00:00:00').
	self assert: aDateAndTime =  (DateAndTime fromString: ' 1901-01-01T00:00').
	self assert: aDateAndTime =  (DateAndTime fromString: ' 1901-01-01T00:00:00+00:00').
!

----- Method: DateAndTimeEpochTest>>testHash (in category 'testing') -----
testHash
	self assert: aDateAndTime hash =    DateAndTime new hash.
	self assert: aDateAndTime hash =     112557138
!

----- Method: DateAndTimeEpochTest>>testHour (in category 'testing') -----
testHour
	self assert: aDateAndTime hour =    aDateAndTime hour24.
	self assert: aDateAndTime hour =    0.
	self assert: aDateAndTime hour =    aDateAndTime hours
!

----- Method: DateAndTimeEpochTest>>testHour12 (in category 'testing') -----
testHour12
	self assert: aDateAndTime hour12  = DateAndTime new hour12.
	self assert: aDateAndTime hour12  = 12
!

----- Method: DateAndTimeEpochTest>>testIsLeapYear (in category 'testing') -----
testIsLeapYear
	self deny: aDateAndTime isLeapYear
!

----- Method: DateAndTimeEpochTest>>testJulianDayNumber (in category 'testing') -----
testJulianDayNumber
	self assert: aDateAndTime =  (DateAndTime julianDayNumber: 2415386).
	self assert: aDateAndTime julianDayNumber = 2415386.!

----- Method: DateAndTimeEpochTest>>testLessThan (in category 'testing') -----
testLessThan
	self assert: aDateAndTime  < (aDateAndTime + '1:00:00:00').
	self assert: aDateAndTime + -1 < aDateAndTime.
	!

----- Method: DateAndTimeEpochTest>>testMeridianAbbreviation (in category 'testing') -----
testMeridianAbbreviation
	self assert: aDateAndTime meridianAbbreviation = 'AM'.

	!

----- Method: DateAndTimeEpochTest>>testMiddleOf (in category 'testing') -----
testMiddleOf
	self assert: (aDateAndTime middleOf: '2:00:00:00' asDuration) = 
	 (Timespan starting: '12-31-1900' asDate duration: 2 days).
	
!

----- Method: DateAndTimeEpochTest>>testMidnight (in category 'testing') -----
testMidnight
	self assert: aDateAndTime midnight =  aDateAndTime
!

----- Method: DateAndTimeEpochTest>>testMinus (in category 'testing') -----
testMinus
	self assert: aDateAndTime - aDateAndTime =  '0:00:00:00' asDuration.
	self assert: aDateAndTime - '0:00:00:00' asDuration = aDateAndTime.
	self assert: aDateAndTime - aDuration =  (DateAndTime year: 1900 month: 12 day: 30 hour: 21 minute: 56 second: 55 nanoSecond: 999999995 offset: 0 hours ).
	" I believe this Failure is a bug in the nanosecond part of (DateAndTime >> year:month:day:hour:minute:second:nanoSecond:offset:)" !

----- Method: DateAndTimeEpochTest>>testMinute (in category 'testing') -----
testMinute
	self assert: aDateAndTime minute =  0

!

----- Method: DateAndTimeEpochTest>>testMinutes (in category 'testing') -----
testMinutes
	self assert: aDateAndTime minutes = 0
!

----- Method: DateAndTimeEpochTest>>testMonth (in category 'testing') -----
testMonth
	self assert: aDateAndTime month  = 1.
	self assert: aDateAndTime monthAbbreviation = 'Jan'.
	self assert: aDateAndTime monthName = 'January'.
	self assert: aDateAndTime monthIndex = 1.!

----- Method: DateAndTimeEpochTest>>testNanoSecond (in category 'testing') -----
testNanoSecond
	self assert: aDateAndTime nanoSecond =  0

!

----- Method: DateAndTimeEpochTest>>testNew (in category 'testing') -----
testNew
	self assert: aDateAndTime =  (DateAndTime new).
!

----- Method: DateAndTimeEpochTest>>testNoon (in category 'testing') -----
testNoon
	self assert: aDateAndTime noon = '1901-01-01T12:00:00+00:00' asDateAndTime!

----- Method: DateAndTimeEpochTest>>testNow (in category 'testing') -----
testNow
	self deny: aDateAndTime =  (DateAndTime now).
!

----- Method: DateAndTimeEpochTest>>testOffset (in category 'testing') -----
testOffset
	self assert: aDateAndTime offset =  '0:00:00:00' asDuration.
     self assert: (aDateAndTime offset: '0:12:00:00') =  '1901-01-01T00:00:00+12:00' asDateAndTime!

----- Method: DateAndTimeEpochTest>>testPlus (in category 'testing') -----
testPlus
	self assert: aDateAndTime + '0:00:00:00' = aDateAndTime.
	self assert: aDateAndTime + 0 = aDateAndTime.
	self assert: aDateAndTime + aDuration = (DateAndTime year: 1901 month: 1 day: 2 hour: 2 minute: 3 second: 4 nanoSecond: 5 offset: 0 hours )
	" I believe this is a bug in the nanosecond part of (DateAndTime >> year:month:day:hour:minute:second:nanoSecond:offset:)"
	
!

----- Method: DateAndTimeEpochTest>>testPrintOn (in category 'testing') -----
testPrintOn
	| ref ws |
	ref := '1901-01-01T00:00:00+00:00'.
	ws := '' writeStream.
	aDateAndTime printOn: ws.
	self assert: ws contents = ref.
	ref  := 'a TimeZone(ETZ)'.
	ws := '' writeStream.
	aTimeZone printOn:  ws.
	self assert: ws contents = ref!

----- Method: DateAndTimeEpochTest>>testSecond (in category 'testing') -----
testSecond
	self assert: aDateAndTime second =  0

!

----- Method: DateAndTimeEpochTest>>testSeconds (in category 'testing') -----
testSeconds
	self assert: aDateAndTime seconds =  0

!

----- Method: DateAndTimeEpochTest>>testTicks (in category 'testing') -----
testTicks
	self assert: aDateAndTime ticks =  (DateAndTime julianDayNumber: 2415386) ticks.
	self assert: aDateAndTime ticks = #(2415386 0 0)!

----- Method: DateAndTimeEpochTest>>testTicksOffset (in category 'testing') -----
testTicksOffset
	self assert: aDateAndTime =  (aDateAndTime ticks:  #(2415386 0 0) offset: DateAndTime localOffset).
!

----- Method: DateAndTimeEpochTest>>testTo (in category 'testing') -----
testTo
	self assert: (aDateAndTime to: aDateAndTime) = (DateAndTime new to: DateAndTime new) 
	"MessageNotUnderstood: UndefinedObject>>starting:ending:  where UndefinedObject is Timespan "!

----- Method: DateAndTimeEpochTest>>testToBy (in category 'testing') -----
testToBy
	self assert: (aDateAndTime to: aDateAndTime + 10 days by: 5 days) = 
				(DateAndTime new to: DateAndTime new + 10 days by: 5 days ) 
	"MessageNotUnderstood: UndefinedObject>>starting:ending:  where UndefinedObject is Timespan "!

----- Method: DateAndTimeEpochTest>>testToByDo (in category 'testing') -----
testToByDo
	"self assert: (aDateAndTime to: aDateAndTime + 10 days by: 5 days do: []) =  "
	"MessageNotUnderstood: UndefinedObject>>starting:ending:  where UndefinedObject is Timespan "!

----- Method: DateAndTimeEpochTest>>testToday (in category 'testing') -----
testToday
	self deny: aDateAndTime =  (DateAndTime today).
!

----- Method: DateAndTimeEpochTest>>testTommorrow (in category 'testing') -----
testTommorrow
	self assert: (DateAndTime today + 24 hours) =  (DateAndTime tomorrow).
	self deny: aDateAndTime =  (DateAndTime tomorrow).
     "MessageNotUnderstood: Date class>>starting:"!

----- Method: DateAndTimeEpochTest>>testUtcOffset (in category 'testing') -----
testUtcOffset
     self assert: (aDateAndTime utcOffset: '0:12:00:00') =  '1901-01-01T12:00:00+12:00' asDateAndTime!

----- Method: DateAndTimeEpochTest>>testYear (in category 'testing') -----
testYear
	self assert: aDateAndTime year = 1901.

	!

----- Method: DateAndTimeEpochTest>>testYearDay (in category 'testing') -----
testYearDay
	self assert: aDateAndTime =  (DateAndTime year: 1901 day: 1).
!

----- Method: DateAndTimeEpochTest>>testYearDayHourMinuteSecond (in category 'testing') -----
testYearDayHourMinuteSecond
	self assert: aDateAndTime =  (DateAndTime year: 1901 day: 1 hour: 0 minute: 0 second: 0).
!

----- Method: DateAndTimeEpochTest>>testYearMonthDay (in category 'testing') -----
testYearMonthDay
	self assert: aDateAndTime =  (DateAndTime year: 1901 month: 1 day: 1).
!

----- Method: DateAndTimeEpochTest>>testYearMonthDayHourMinuteSecond (in category 'testing') -----
testYearMonthDayHourMinuteSecond
	self assert: aDateAndTime =  (DateAndTime year: 1901 month: 1 day: 1 hour: 0 minute: 0 second: 0).
!

----- Method: DateAndTimeEpochTest>>testYearMonthDayHourMinuteSecondNanosSecondOffset (in category 'testing') -----
testYearMonthDayHourMinuteSecondNanosSecondOffset
	self assert: aDateAndTime =  (DateAndTime year: 1901 month: 1 day: 1 hour: 0 minute: 0 second: 0 nanoSecond: 0 offset:0 hours ).
	self assert: ((DateAndTime year: 1 month: 1 day: 1 hour: 0 minute: 0 second: 0 nanoSecond: 0 offset: 0 hours ) +
				(Duration days: 1 hours: 2 minutes: 3 seconds: 4  nanoSeconds: 5) ) =  	
				(DateAndTime year: 1 month: 1 day: 2 hour: 2 minute: 3 second: 4 nanoSecond: 5 offset: 0 hours ) 
	" I believe this is a bug in the nanosecond part of (DateAndTime >> year:month:day:hour:minute:second:nanoSecond:offset:)"" I believe this is a bug in the nanosecond part of (DateAndTime >> year:month:day:hour:minute:second:nanoSecond:offset:)"   
!

----- Method: DateAndTimeEpochTest>>testYesterday (in category 'testing') -----
testYesterday
	self deny: aDateAndTime =  (DateAndTime yesterday).
!

----- Method: DateAndTimeEpochTest>>testtimeZone (in category 'testing') -----
testtimeZone
	self assert: aDateAndTime timeZoneName	= 'Universal Time'.
	self assert: aDateAndTime timeZoneAbbreviation	=  'UTC'

!

TestCase subclass: #DateAndTimeLeapTest
	instanceVariableNames: 'aDateAndTime aDuration aTimeZone localTimeZoneToRestore'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Chronology-Tests'!

!DateAndTimeLeapTest commentStamp: 'tlk 1/6/2004 17:54' prior: 0!
I represent one of several Sunit test Cases intentended to provide complete coverage for the Chronology set of classes as part of the external testing. tlk.
My fixtures are:
aDateAndTime = February 29, 2004 1:33 PM with offset: 2 hours
aDuration = 15 days, 14 hours, 13 minutes, 12 seconds and 11 nano seconds.
aTimeZone =  Grenwhich Meridian (local offset = 0 hours) !

----- Method: DateAndTimeLeapTest>>setUp (in category 'running') -----
setUp
	localTimeZoneToRestore := DateAndTime localTimeZone.
	DateAndTime localTimeZone: TimeZone default.
	aDateAndTime := (DateAndTime year: 2004 month: 2 day: 29 hour: 13 minute: 33 second: 0 offset: 2 hours).
	aTimeZone := TimeZone default.
	aDuration := Duration days: 0 hours: 13 minutes: 33 seconds: 0 nanoSeconds: 0
!

----- Method: DateAndTimeLeapTest>>tearDown (in category 'running') -----
tearDown
     DateAndTime localTimeZone: localTimeZoneToRestore.
     "wish I could remove the time zones I added earlier, tut there is no method for that"
!

----- Method: DateAndTimeLeapTest>>testAsDate (in category 'testing') -----
testAsDate
	self assert: (aDateAndTime offset: DateAndTime localTimeZone offset) asDate = 'February 29, 2004' asDate!

----- Method: DateAndTimeLeapTest>>testAsDuration (in category 'testing') -----
testAsDuration
	self assert: aDateAndTime asDuration =  aDuration
	
!

----- Method: DateAndTimeLeapTest>>testAsLocal (in category 'testing') -----
testAsLocal
	self assert: aDateAndTime asLocal =  aDateAndTime.
	self assert: aDateAndTime asLocal = (aDateAndTime utcOffset: aDateAndTime class localOffset)

	
!

----- Method: DateAndTimeLeapTest>>testAsMonth (in category 'testing') -----
testAsMonth
	self assert:
		(aDateAndTime offset: Month defaultOffset) asMonth =
			(Month
				month: 'February'
				year: 2004)!

----- Method: DateAndTimeLeapTest>>testAsNanoSeconds (in category 'testing') -----
testAsNanoSeconds
	self assert: aDateAndTime asNanoSeconds =  aDuration asNanoSeconds.
	self assert: aDateAndTime asNanoSeconds = 48780000000000
	
!

----- Method: DateAndTimeLeapTest>>testAsSeconds (in category 'testing') -----
testAsSeconds
	self assert: aDuration asSeconds = 48780.
	self assert: aDateAndTime asSeconds = 3255514380!

----- Method: DateAndTimeLeapTest>>testAsTime (in category 'testing') -----
testAsTime
	self assert: aDateAndTime asTime = (Time hour: 13 minute: 33 second: 0)
!

----- Method: DateAndTimeLeapTest>>testAsTimeStamp (in category 'testing') -----
testAsTimeStamp
	self assert: aDateAndTime asTimeStamp =  ((TimeStamp readFrom: '2-29-2004 1:33 pm' readStream) offset: 2 hours).

!

----- Method: DateAndTimeLeapTest>>testAsUTC (in category 'testing') -----
testAsUTC
	self assert: aDateAndTime asUTC =  aDateAndTime

          !

----- Method: DateAndTimeLeapTest>>testAsWeek (in category 'testing') -----
testAsWeek
	self assert: (aDateAndTime offset: DateAndTime localTimeZone offset) asWeek = (Week starting: '02-29-2004' asDate)!

----- Method: DateAndTimeLeapTest>>testAsYear (in category 'testing') -----
testAsYear
	| year |
	year := (aDateAndTime offset: DateAndTime localTimeZone offset) asYear.
	self assert: year = (Year starting: '02-29-2004' asDate).
	self deny: year = (Year starting: '01-01-2004' asDate)!

----- Method: DateAndTimeLeapTest>>testDay (in category 'testing') -----
testDay
	self assert: aDateAndTime day =   60. 
	self deny: aDateAndTime day =   29 !

----- Method: DateAndTimeLeapTest>>testDayMonthYearDo (in category 'testing') -----
testDayMonthYearDo
	self assert: (aDateAndTime dayMonthYearDo: [:eachDay :eachMonth :eachYear |  eachYear])  = 2004.
	self assert: (aDateAndTime dayMonthYearDo: [:eachDay :eachMonth :eachYear |  eachMonth]) = 2.
	self assert: (aDateAndTime dayMonthYearDo: [:eachDay :eachMonth :eachYear |  eachDay]) = 29.
!

----- Method: DateAndTimeLeapTest>>testDayOfMonth (in category 'testing') -----
testDayOfMonth
	self assert: aDateAndTime dayOfMonth  = 29.
!

----- Method: DateAndTimeLeapTest>>testDayOfWeek (in category 'testing') -----
testDayOfWeek
	self assert: aDateAndTime dayOfWeek  = 1.
	self assert: aDateAndTime dayOfWeekAbbreviation = 'Sun'.
	self assert: aDateAndTime dayOfWeekName = 'Sunday'.
!

----- Method: DateAndTimeLeapTest>>testDayOfYear (in category 'testing') -----
testDayOfYear
	self assert: aDateAndTime dayOfYear  = 60.

!

----- Method: DateAndTimeLeapTest>>testDaysInMonth (in category 'testing') -----
testDaysInMonth
	self assert: aDateAndTime daysInMonth  = 29.

!

----- Method: DateAndTimeLeapTest>>testDaysInYear (in category 'testing') -----
testDaysInYear
	self assert: aDateAndTime daysInYear  = 366.

!

----- Method: DateAndTimeLeapTest>>testDaysLeftInYear (in category 'testing') -----
testDaysLeftInYear
	self assert: aDateAndTime daysLeftInYear  = 306.

!

----- Method: DateAndTimeLeapTest>>testFirstDayOfMonth (in category 'testing') -----
testFirstDayOfMonth
	self deny: aDateAndTime firstDayOfMonth =  1.
	self assert: aDateAndTime firstDayOfMonth = 32
!

----- Method: DateAndTimeLeapTest>>testFromString (in category 'testing') -----
testFromString
	self assert: aDateAndTime =  (DateAndTime fromString: ' 2004-02-29T13:33:00+02:00').

!

----- Method: DateAndTimeLeapTest>>testHash (in category 'testing') -----
testHash
	self assert: aDateAndTime hash =      16256473
!

----- Method: DateAndTimeLeapTest>>testHour (in category 'testing') -----
testHour
	self assert: aDateAndTime hour =    aDateAndTime hour24.
	self assert: aDateAndTime hour =    13.
	self assert: aDateAndTime hour =    aDateAndTime hours
!

----- Method: DateAndTimeLeapTest>>testHour12 (in category 'testing') -----
testHour12
	self assert: aDateAndTime hour12  =   1.
!

----- Method: DateAndTimeLeapTest>>testIsLeapYear (in category 'testing') -----
testIsLeapYear
	self assert: aDateAndTime isLeapYear
!

----- Method: DateAndTimeLeapTest>>testLessThan (in category 'testing') -----
testLessThan
	self assert: aDateAndTime  < (aDateAndTime + '1:00:00:00').
	self assert: aDateAndTime + -1 < aDateAndTime.
	!

----- Method: DateAndTimeLeapTest>>testMeridianAbbreviation (in category 'testing') -----
testMeridianAbbreviation
	self assert: aDateAndTime meridianAbbreviation = 'PM'.

	!

----- Method: DateAndTimeLeapTest>>testMiddleOf (in category 'testing') -----
testMiddleOf
	self assert: (aDateAndTime middleOf: aDuration)  = 
	 (Timespan starting: (DateAndTime year: 2004 month: 2 day: 29 hour: 6 minute: 46 second: 30 offset: 2 hours)
	duration: (Duration days: 0 hours: 13 minutes: 33 seconds: 0 nanoSeconds: 0 ))
	!

----- Method: DateAndTimeLeapTest>>testMidnight (in category 'testing') -----
testMidnight
	| midnight |
	midnight := (aDateAndTime offset: DateAndTime localTimeZone offset) midnight.
	self assert: midnight = '2004-02-29T00:00:00+00:00' asDateAndTime.
	self deny: midnight = '2004-02-29T00:00:00+02:00' asDateAndTime!

----- Method: DateAndTimeLeapTest>>testMinute (in category 'testing') -----
testMinute
	self assert: aDateAndTime minute =  33

!

----- Method: DateAndTimeLeapTest>>testMinutes (in category 'testing') -----
testMinutes
	self assert: aDateAndTime minutes = 33
!

----- Method: DateAndTimeLeapTest>>testMonth (in category 'testing') -----
testMonth
	self assert: aDateAndTime month  = 2.
	self assert: aDateAndTime monthAbbreviation = 'Feb'.
	self assert: aDateAndTime monthName = 'February'.
	self assert: aDateAndTime monthIndex = 2.!

----- Method: DateAndTimeLeapTest>>testMonthParsing (in category 'testing') -----
testMonthParsing
	self assert:
		(Month readFrom: 'Feb 2011' readStream) =
			(Month
				month: 2
				year: 2011)!

----- Method: DateAndTimeLeapTest>>testNanoSecond (in category 'testing') -----
testNanoSecond
	self assert: aDateAndTime nanoSecond =  0

!

----- Method: DateAndTimeLeapTest>>testNoon (in category 'testing') -----
testNoon
	self assert: aDateAndTime noon =  '2004-02-29T12:00:00+00:00' asDateAndTime!

----- Method: DateAndTimeLeapTest>>testOffset (in category 'testing') -----
testOffset
	self assert: aDateAndTime offset =  '0:02:00:00' asDuration.
     self assert: (aDateAndTime offset: '0:12:00:00') =  '2004-02-29T13:33:00+12:00' asDateAndTime!

----- Method: DateAndTimeLeapTest>>testPrintOn (in category 'testing') -----
testPrintOn
	| ref ws |
	ref := '2004-02-29T13:33:00+02:00'.
	ws := '' writeStream.
	aDateAndTime printOn: ws.
	self assert: ws contents = ref.
	ref  := 'a TimeZone(UTC)'.
	ws := '' writeStream.
	aTimeZone printOn:  ws.
	self assert: ws contents = ref	!

----- Method: DateAndTimeLeapTest>>testSecond (in category 'testing') -----
testSecond
	self assert: aDateAndTime second =  0

!

----- Method: DateAndTimeLeapTest>>testSeconds (in category 'testing') -----
testSeconds
	self assert: aDateAndTime seconds =  0

!

----- Method: DateAndTimeLeapTest>>testTicks (in category 'testing') -----
testTicks
	self assert: aDateAndTime ticks =  ((DateAndTime julianDayNumber: 2453065) + 48780 seconds) ticks.
	self assert: aDateAndTime ticks =  #(2453065 48780 0)!

----- Method: DateAndTimeLeapTest>>testTicksOffset (in category 'testing') -----
testTicksOffset
	self assert: aDateAndTime =  (aDateAndTime ticks:  #(2453065 48780 0) offset: DateAndTime localOffset).

!

----- Method: DateAndTimeLeapTest>>testUtcOffset (in category 'testing') -----
testUtcOffset
     self assert: (aDateAndTime utcOffset: '0:02:00:00') =  '2004-02-29T13:33:00+02:00' asDateAndTime!

----- Method: DateAndTimeLeapTest>>testYear (in category 'testing') -----
testYear
	self assert: aDateAndTime year = 2004.

	!

----- Method: DateAndTimeLeapTest>>testYearDayHourMinuteSecond (in category 'testing') -----
testYearDayHourMinuteSecond
	self assert: aDateAndTime =  ((DateAndTime year: 2004 day: 60 hour: 13 minute: 33 second: 0) offset: 2 hours).
!

----- Method: DateAndTimeLeapTest>>testYearMonthDayHourMinuteSecond (in category 'testing') -----
testYearMonthDayHourMinuteSecond
	self assert: aDateAndTime =  ((DateAndTime year: 2004 month: 2 day: 29 hour: 13 minute: 33 second: 0) offset: 2 hours).
!

----- Method: DateAndTimeLeapTest>>testtimeZone (in category 'testing') -----
testtimeZone
	self assert: aDateAndTime timeZoneName	= 'Universal Time'.
	self assert: aDateAndTime timeZoneAbbreviation	=  'UTC'

!

TestCase subclass: #TimespanDoSpanAYearTest
	instanceVariableNames: 'aTimespan aDuration aDate'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Chronology-Tests'!

!TimespanDoSpanAYearTest commentStamp: 'tlk 1/6/2004 17:55' prior: 0!
I am one of several Sunit test Cases intentended to provide complete coverage for the Chronology set of classes as part of the external testing. See DateAndTimeEpochTestCase for a complete list. tlk.
My fixtures include a Timespan that crosses over a year boundary:
aDate = December 25, 2004, midnight
aDuration = 91 days
aTimeSpan= 91 days, starting December 25, 2004, midnight!

----- Method: TimespanDoSpanAYearTest>>setUp (in category 'running') -----
setUp
	aDate := DateAndTime year: 2004 month: 12 day: 25 hour: 0 minute: 0 second: 0.
	aDuration := Duration days: 91 hours: 0 minutes: 0 seconds: 0 nanoSeconds: 0.

	aTimespan := Timespan starting: aDate duration: aDuration!

----- Method: TimespanDoSpanAYearTest>>testMonthsDo (in category 'testing') -----
testMonthsDo

	| monthArray |

	monthArray := Array
				with: (Month starting: (DateAndTime year: 2004 day: 355) duration: 31 days)
				with: (Month starting: (DateAndTime year: 2005 day: 1) duration: 31 days)
				with: (Month starting: (DateAndTime year: 2005 day: 32) duration: 29 days)
				with: (Month starting: (DateAndTime year: 2005 day: 61) duration: 31 days).
				
	self assert: aTimespan months = monthArray!

----- Method: TimespanDoSpanAYearTest>>testNext (in category 'testing') -----
testNext

	self assert: aTimespan next
			= (Timespan
					starting: (DateAndTime
							year: 2005
							month: 3
							day: 26
							hour: 0
							minute: 0
							second: 0)
					duration: aDuration)!

----- Method: TimespanDoSpanAYearTest>>testWeeksDo (in category 'testing') -----
testWeeksDo
	| weeks weekArray |
	weeks := aTimespan weeks.
	self assert: weeks size = ((aDuration days / 7.0) ceiling + 1).

	weekArray := OrderedCollection new.
	weekArray
		addLast: (Week starting: (DateAndTime year: 2004 month: 12 day: 19) duration: 7 days);
		addLast: (Week starting: (DateAndTime year: 2004 month: 12 day: 26) duration: 7 days).

	2 to: 79 by: 7 do:
		[ :i | weekArray
				addLast: (Week starting: (DateAndTime year: 2005 day: i) duration: 7 days) ].

	weekArray := weekArray asArray.
	self assert: aTimespan weeks = weekArray
!

----- Method: TimespanDoSpanAYearTest>>testYearsDo (in category 'testing') -----
testYearsDo
	| yearArray |
	yearArray := Array
				with: (Year
						starting: (DateAndTime
								year: 2004
								month: 12
								day: 25)
						duration: 366 days).
	self assert: aTimespan years = yearArray
!

TestCase subclass: #TimespanDoTest
	instanceVariableNames: 'aTimespan aDuration aDate'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Chronology-Tests'!

!TimespanDoTest commentStamp: 'tlk 1/6/2004 17:55' prior: 0!
I am one of several Sunit test Cases intentended to provide complete coverage for the Chronology set of classes as part of the external testing. See DateAndTimeEpochTestCase for a complete list.  tlk.
My fixtures are:
aDate = January 8, 2003, midnight
aDuration = 91 days
aTimeSpan= 91 days, starting January 8, 2003, midnight
!

----- Method: TimespanDoTest>>setUp (in category 'running') -----
setUp
	aDate := DateAndTime
				year: 2003
				month: 01
				day: 07
				hour: 0
				minute: 0
				second: 0.
	aDuration := Duration
				days: 91
				hours: 0
				minutes: 0
				seconds: 0
				nanoSeconds: 0.
	aTimespan := Timespan starting: aDate makeUTC duration: aDuration!

----- Method: TimespanDoTest>>testDatesDo (in category 'testing') -----
testDatesDo
	| dateArray |
	dateArray := OrderedCollection new.
	7
		to: 97
		do: [:each | dateArray
				addLast: (Date year: 2003 day: each)].
	dateArray := dateArray asArray.
	self assert: aTimespan dates = dateArray!

----- Method: TimespanDoTest>>testDoWith (in category 'testing') -----
testDoWith
	| count |
	count := 0.
	aTimespan
		do: [:each | count := count + 1]
		with: (Timespan
				starting: aDate
				duration: 7 days).
	self assert: count = 13!

----- Method: TimespanDoTest>>testDoWithWhen (in category 'testing') -----
testDoWithWhen
	| count |
	count := 0.
	aTimespan
		do: [:each | count := count + 1]
		with: (Timespan starting: aDate duration: 7 days)
		when: [:each | count < 5].
	self assert: count = 5	
!

----- Method: TimespanDoTest>>testEveryDo (in category 'testing') -----
testEveryDo
	|count  duration |
	count := 0.
	duration := 7 days.
	(aTimespan
			every: duration
			do: [:each | count := count + 1]).
	self assert: count = 13
			!

----- Method: TimespanDoTest>>testMonthsDo (in category 'testing') -----
testMonthsDo
	| monthArray |
	monthArray := Array
				with: (Month
						starting: (DateAndTime year: 2003 day: 1 hour: 0 minute: 0 second: 0 offset: Month defaultOffset)
						duration: 31 days)
				with: (Month
						starting: (DateAndTime year: 2003 day: 32 hour: 0 minute: 0 second: 0 offset: Month defaultOffset)
						duration: 28 days)
				with: (Month
						starting: (DateAndTime year: 2003 day: 60 hour: 0 minute: 0 second: 0 offset: Month defaultOffset)
						duration: 31 days)		
				with: (Month
						starting: (DateAndTime year: 2003 day: 91 hour: 0 minute: 0 second: 0 offset: Month defaultOffset)
						duration: 30 days).
	self assert: aTimespan months = monthArray!

----- Method: TimespanDoTest>>testNext (in category 'testing') -----
testNext
	self assert: aTimespan next 
			= (Timespan
					starting: (DateAndTime
							year: 2003
							month: 4
							day: 8
							hour: 0
							minute: 0
							second: 0 
							offset: Timespan defaultOffset)
					duration: aDuration)!

----- Method: TimespanDoTest>>testWeeksDo (in category 'testing') -----
testWeeksDo
	| weekArray |
	weekArray := OrderedCollection new.
	7
		to: 98
		by: 7
		do: [:each | weekArray
				addLast: (Week
						starting: (DateAndTime year: 2003 day: each hour: 0 minute: 0 second: 0 offset: Week defaultOffset)
						duration: 7 days)].
	weekArray := weekArray asArray.
	self assert: aTimespan weeks = weekArray
!

----- Method: TimespanDoTest>>testYearsDo (in category 'testing') -----
testYearsDo
	| yearArray |
	yearArray := Array
				with: (Year
						starting: (DateAndTime year: 2003 day: 7 hour: 0 minute: 0 second: 0 offset: Year defaultOffset)
						duration: 365 days).
	self assert: aTimespan years contents = yearArray contents!

TestCase subclass: #YearMonthWeekTest
	instanceVariableNames: 'restoredStartDay restoredTimeZone'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Chronology-Tests'!

!YearMonthWeekTest commentStamp: 'tlk 1/6/2004 17:55' prior: 0!
I am one of several Sunit test Cases intentended to provide complete coverage for the Chronology set of classes as part of the external testing. See DateAndEpochTestCase for a complete list.  tlk.
I have no fixtures but do make sure to restore anything I change.!

----- Method: YearMonthWeekTest>>setUp (in category 'running') -----
setUp
	restoredStartDay := Week startDay.
	restoredTimeZone := DateAndTime localTimeZone.

	Week startDay: #Sunday.
	DateAndTime localTimeZone: (TimeZone timeZones detect: [:tz | tz abbreviation = 'GMT']).!

----- Method: YearMonthWeekTest>>tearDown (in category 'running') -----
tearDown
	Week startDay: restoredStartDay.
	DateAndTime localTimeZone: restoredTimeZone.!

----- Method: YearMonthWeekTest>>testDaysInMonth (in category 'testing') -----
testDaysInMonth
	self assert: (Month daysInMonth: 2 forYear: 2000) = 29.
	self assert: (Month daysInMonth: 2 forYear: 2001) = 28.
	self assert: (Month  daysInMonth: 2 forYear: 2004) = 29.
	self assert: (Month  daysInMonth: 2 forYear: 2100) = 28.
	
	self assert: (Month  daysInMonth: 'January' forYear: 2003) = 31.
	self assert: (Month  daysInMonth: 'February' forYear: 2003) = 28.
	self assert: (Month  daysInMonth: 'March' forYear: 2003) = 31.
	self assert: (Month  daysInMonth: 'April' forYear: 2003) = 30.
	self assert: (Month  daysInMonth: 'May' forYear: 2003) = 31.
	self assert: (Month  daysInMonth: 'June' forYear: 2003) = 30.
	self assert: (Month  daysInMonth: 'July' forYear: 2003) = 31.
	self assert: (Month  daysInMonth: 'August' forYear: 2003) = 31.
	self assert: (Month  daysInMonth: 'September' forYear: 2003) = 30.
	self assert: (Month  daysInMonth: 'October' forYear: 2003) = 31.
	self assert: (Month  daysInMonth: 'November' forYear: 2003) = 30.
	self assert: (Month  daysInMonth: 'December' forYear: 2003) = 31.!

----- Method: YearMonthWeekTest>>testDaysInYear (in category 'testing') -----
testDaysInYear
	self assert: (Year daysInYear: 2000) = 366.
	self assert: (Year daysInYear: 2001) = 365.
	self assert: (Year daysInYear: 2004) = 366.
	self assert: (Year daysInYear: 2100) = 365.
	self assert: (Year daysInYear: 2003) = 365.!

----- Method: YearMonthWeekTest>>testIndexOfDay (in category 'testing') -----
testIndexOfDay
	self assert: (Week indexOfDay: 'Friday') = 6.

!

----- Method: YearMonthWeekTest>>testIsLeapYear (in category 'testing') -----
testIsLeapYear
	self assert: (Year isLeapYear: 2000).
	self deny: (Year isLeapYear: 2001).
	self assert: (Year isLeapYear: 2004).
	self deny: (Year isLeapYear: 2100).
	self deny: (Year isLeapYear: 2002).!

----- Method: YearMonthWeekTest>>testMonthPrintOn (in category 'testing') -----
testMonthPrintOn
	| aMonth ws |
	aMonth := Month starting: DateAndTime new duration: 31 days.
	ws := '' writeStream.
	aMonth printOn: ws.
	self assert: ws contents = 'January 1901'.!

----- Method: YearMonthWeekTest>>testStartDay (in category 'testing') -----
testStartDay
	Week startDay: 'Wednesday'.
	self assert: Week startDay = 'Wednesday'.
	Week startDay: 'Thursday'.
	self assert: Week startDay = 'Thursday'.

!

----- Method: YearMonthWeekTest>>testWeekPrintOn (in category 'testing') -----
testWeekPrintOn
	| aWeek cs rw |
	aWeek := Week starting: (DateAndTime year: 1900 month: 12 day: 31).
	cs := 'a Week starting: 1900-12-30T00:00:00+00:00'.
	rw := WriteStream on: ''.
	aWeek printOn: rw.
	self assert: rw contents = cs!

----- Method: YearMonthWeekTest>>testYearPrintOn (in category 'testing') -----
testYearPrintOn
	| aYear ws |
	aYear := Year starting: DateAndTime new duration: 365 days.
	ws := '' writeStream.
	aYear printOn: ws.
	self assert: ws contents = 'a Year (1901)'.!

ClassTestCase subclass: #DateAndTimeTest
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Chronology-Tests'!

----- Method: DateAndTimeTest>>classToBeTested (in category 'Coverage') -----
classToBeTested

	^ DateAndTime

!

----- Method: DateAndTimeTest>>selectorsToBeIgnored (in category 'Coverage') -----
selectorsToBeIgnored

	| private | 
	private := #( #printOn: ).

	^ super selectorsToBeIgnored, private
!

----- Method: DateAndTimeTest>>testArithmeticAcrossDateBoundary (in category 'Tests') -----
testArithmeticAcrossDateBoundary

	| t1 t2 |
	t1 := '2004-01-07T11:55:00+00:00' asDateAndTime. 
	t2 := t1 - ( (42900+1) seconds).  

	self 
		assert: t2 = ('2004-01-06T23:59:59+00:00' asDateAndTime)
		
!

----- Method: DateAndTimeTest>>testAsStringFromString (in category 'Tests') -----
testAsStringFromString
	"Convert to string then back, verify same date and time. Skip years in the
	range 0 to 99 because they are interpreted relative to 2000."

	| day hour dt min mo nano offset sec dtNew s |
	mo := 12.
	day := 2.
	hour := 2.
	min := 3.
	sec := 4.
	nano := 5.
	offset := 6 hours.
	(-2000 to: -1) , (100 to: 5000) do: [:yr |
		dt := DateAndTime 
			year: yr month: mo day: day 
			hour: hour minute: min second: sec nanoSecond: nano 
			offset: offset.
		s := dt asString.
		dtNew := DateAndTime fromString: s.
		self assert: dt equals: dtNew].
!

----- Method: DateAndTimeTest>>testDateTimeDenotation1 (in category 'Tests') -----
testDateTimeDenotation1
  "DateAndTimeTest new testDateTimeDenotation1"
	
	 " Detroit is 5 hours behind UTC, this offset to UTC is therefore written with a minus sign. This example tests the correct interpretation of the DateAndTime denotation. "

	| twoPmInLondon twoPmUTCInLocalTimeOfDetroit nineAmInDetroit |
	twoPmInLondon := DateAndTime
				year: 2004
				month: 11
				day: 2
				hour: 14
				minute: 0
				second: 0
				offset: 0 hours.
	twoPmUTCInLocalTimeOfDetroit := twoPmInLondon utcOffset: -5 hours.
	nineAmInDetroit  := '2004-11-02T09:00:00-05:00' asDateAndTime.
	self assert:  twoPmUTCInLocalTimeOfDetroit = nineAmInDetroit.
	
!

----- Method: DateAndTimeTest>>testDateTimeDenotation2 (in category 'Tests') -----
testDateTimeDenotation2
  "DateAndTimeTest new testDateTimeDenotation2"
	
	 " Moscow is 3 hours ahead UTC, this offset to UTC is therefore positive. This example tests the correct interpretation of the DateAndTime denotation. "

	| lateEveningInLondon lateEveningInLocalTimeOfMoscow
	 localMoscowTimeFromDenotation |
	lateEveningInLondon := DateAndTime
				year: 2004
				month: 11
				day: 30
				hour: 23
				minute: 30
				second: 0
				offset: 0 hours.
	lateEveningInLocalTimeOfMoscow := lateEveningInLondon utcOffset: 3 hours.
	localMoscowTimeFromDenotation  := '2004-12-01T02:30:00+03:00' asDateAndTime.
	self assert:  lateEveningInLocalTimeOfMoscow = localMoscowTimeFromDenotation.
	
!

----- Method: DateAndTimeTest>>testErrorWhenDayIsAfterMonthEnd (in category 'Tests') -----
testErrorWhenDayIsAfterMonthEnd

	self
		should:
			[DateAndTime
				year: 2004
				month: 2
				day: 30]
		raise: Error.!

----- Method: DateAndTimeTest>>testErrorWhenDayIsBeforeMonthStart (in category 'Tests') -----
testErrorWhenDayIsBeforeMonthStart

	self
		should:
			[DateAndTime
				year: 2004
				month: 2
				day: -1]
		raise: Error.

	self
		should:
			[DateAndTime
				year: 2004
				month: 2
				day: 0]
		raise: Error.!

----- Method: DateAndTimeTest>>testFromString (in category 'Tests') -----
testFromString

	| fromString fromStringNoOffset fromStringUTC |
	fromString := DateAndTime fromString: '-1199-01-05T20:33:14.321-05:00'.
	self assert: (fromString printString = '-1199-01-05T20:33:14.321-05:00').
	
	"if no offset is provided, the local offset should be used"
	fromStringNoOffset := DateAndTime fromString: '-1199-01-05T20:33:14.321'.
	self assert: (fromStringNoOffset offset = DateAndTime localOffset).
	
	"if a string contains the UTC designator Z, the local offset should not be used"
	fromStringUTC := DateAndTime fromString: '2011-08-26T18:00:03Z'.
	self assert: (fromStringUTC printString = '2011-08-26T18:00:03+00:00').!

----- Method: DateAndTimeTest>>testHash (in category 'Tests') -----
testHash
	| date0 date1 date2 |
	date0 := DateAndTime unixEpoch.
	date1 := DateAndTime new ticks: (date0 + 1 hours) ticks offset: 0 hours.
	date2 := DateAndTime new ticks: (date0 - 2 hours) ticks offset: -3 hours.
	self assert: (date1 = date2) ==> [date1 hash = date2 hash]!

----- Method: DateAndTimeTest>>testInstanceCreation (in category 'Tests') -----
testInstanceCreation

	| t |
	t := DateAndTime 
			year: 1 month: 1 day: 2 
			hour: 2 minute: 3 second: 4 nanoSecond: 5 
			offset: 6 hours.
	self 
		assert: (t julianDayNumber = 1721427);
		assert: (t offset = 6 hours);
		assert: (t hour = 2);
		assert: (t minute = 3);
		assert: (t second = 4);
		assert: (t nanoSecond = 5).
		
!

----- Method: DateAndTimeTest>>testMonotonicity (in category 'Tests') -----
testMonotonicity

	| t1 t2 t3 t4 |
	t1 := DateAndTime now.
	t2 := DateAndTime now.
	(Delay forMilliseconds: 1000) wait.
	t3 := DateAndTime now.
	t4 := DateAndTime now.

	self
		assert: (	t1 <= t2);
		assert: (	t2 < t3);
		assert: (	t3 <= t4).
!

----- Method: DateAndTimeTest>>testPrecision (in category 'Tests') -----
testPrecision
	"Verify that the clock is returning a value with accuracy of better than 1 second.  For now it seems sufficient to get two values and verify they are not the same."

	self
		assert: (DateAndTime now ~= DateAndTime now)
!

----- Method: DateAndTimeTest>>testPrintString (in category 'Tests') -----
testPrintString

	"(self new setTestSelector: #testPrintString) debug"

	| dt dtNoOffset |
	dt :=DateAndTime
		year: 2004
		month: 11
		day: 2
		hour: 14
		minute: 3
		second: 5
		nanoSecond: 12345
		offset: (Duration seconds: (5 * 3600)).
	self assert: dt printString = '2004-11-02T14:03:05.000012345+05:00'.
	
	self assert: ('2002-05-16T17:20:45.1+01:01' asDateAndTime printString = '2002-05-16T17:20:45.1+01:01').
	self assert:	(' 2002-05-16T17:20:45.02+01:01' asDateAndTime printString = '2002-05-16T17:20:45.02+01:01').  
	self assert:	('2002-05-16T17:20:45.000000009+01:01' asDateAndTime printString =  '2002-05-16T17:20:45.000000009+01:01').
	self assert: ('2002-05-16T17:20:45+00:00' asDateAndTime printString = '2002-05-16T17:20:45+00:00' ).
	self assert: (' 2002-05-16T17:20:45+01:57' asDateAndTime printString = '2002-05-16T17:20:45+01:57').
	self assert: (' 2002-05-16T17:20:45-02:34' asDateAndTime printString = '2002-05-16T17:20:45-02:34').
	self assert: ('2002-05-16T17:20:45+00:00' asDateAndTime printString = '2002-05-16T17:20:45+00:00').
	self assert: ('1997-04-26T01:02:03+01:02:3' asDateAndTime printString = '1997-04-26T01:02:03+01:02:3').

	"When no offset is provided, the local one is used"
	dtNoOffset := '2002-05-16T17:20' asDateAndTime.
	self assert: (('2002-05-16T17:20:00*' match: dtNoOffset printString) and: [dtNoOffset offset = DateAndTime localOffset]).

!

----- Method: DateAndTimeTest>>testReadFrom (in category 'Tests') -----
testReadFrom

	self assert: '-1199-01-05T20:33:14.321-05:00' equals: (DateAndTime readFrom: '-1199-01-05T20:33:14.321-05:00' readStream) printString.
	self assert: '-1199-01-05T20:33:14.321-05:00' equals: '-1199-01-05T20:33:14.321-05:00' asDateAndTime printString.
	self assert: '2002-05-16T17:20:45.1+01:01' equals: '2002-05-16T17:20:45.1+01:01' asDateAndTime printString.
	self assert: '2002-05-16T17:20:45.02+01:01' equals: ' 2002-05-16T17:20:45.02+01:01' asDateAndTime printString.  
	self assert: '2002-05-16T17:20:45.000000009+01:01' equals: '2002-05-16T17:20:45.000000009+01:01' asDateAndTime printString.
	self assert: '2002-05-16T17:20:45+01:57' equals: ' 2002-05-16T17:20:45+01:57' asDateAndTime printString.
	self assert: '2002-05-16T17:20:45-02:34' equals: ' 2002-05-16T17:20:45-02:34' asDateAndTime printString.
	self assert: '2002-05-16T17:20:45+00:00' equals: '2002-05-16T17:20:45+00:00' asDateAndTime printString.
	self assert: '1997-04-26T01:02:03+01:02:3' equals: '1997-04-26T01:02:03+01:02:3' asDateAndTime printString!

----- Method: DateAndTimeTest>>testSmalltalk80Accessors (in category 'Tests') -----
testSmalltalk80Accessors

	| t |
	t := DateAndTime 
			year: 1 month: 1 day: 2 
			hour: 2 minute: 3 second: 4 nanoSecond: 5 
			offset: 6 hours.
	self 
		assert: (t hours = t hours);
		assert: (t minutes = t minute);
		assert: (t seconds = t second).
!

----- Method: DateAndTimeTest>>testTimeZoneEquivalence (in category 'Tests') -----
testTimeZoneEquivalence
  "DateAndTimeTest new testTimeZoneEquivalence"
	"When the clock on the wall in Detroit says 9:00am, the clock on the wall
	in London says 2:00pm. The Duration difference between the corresponding
	DateAndTime values should be zero."
	
	 " Detroit is 5 hours behind UTC, this offset to UTC is therefore written with a minus sign. This example tests both the correct interpretation of the DateAndTime denotation and correct DateAndTime arithmetics. "

	| twoPmInLondon nineAmInDetroit durationDifference |
	twoPmInLondon := '2004-11-02T14:00:00+00:00' asDateAndTime.
	nineAmInDetroit  := '2004-11-02T09:00:00-05:00' asDateAndTime.
	durationDifference := twoPmInLondon - nineAmInDetroit.
	self assert: durationDifference asSeconds = 0.
	self assert: twoPmInLondon = nineAmInDetroit
!

----- Method: DateAndTimeTest>>testTimeZoneEquivalence2 (in category 'Tests') -----
testTimeZoneEquivalence2
  "DateAndTimeTest new testTimeZoneEquivalence2"
	"This example demonstates the fact that
        2004-05-24T22:40:00  UTC  is
        2004-05-25T01:40:00  in Moscow
     (Moscow is 3 hours ahead of UTC)  "

	| thisMoment thisMomentInMoscow |
    thisMoment := DateAndTime year: 2004 month: 5 day: 24 hour: 22 minute: 40.
    thisMomentInMoscow := thisMoment utcOffset: 3 hours.
	self assert: (thisMoment - thisMomentInMoscow) asSeconds = 0.
	self assert: thisMoment = thisMomentInMoscow
!

ClassTestCase subclass: #DateTest
	instanceVariableNames: 'date aDate aTime'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Chronology-Tests'!

!DateTest commentStamp: 'brp 7/26/2003 16:58' prior: 0!
This is the unit test for the class Date. !

----- Method: DateTest>>classToBeTested (in category 'Coverage') -----
classToBeTested

	^ self dateClass!

----- Method: DateTest>>dateClass (in category 'Private') -----
dateClass

	^ Date!

----- Method: DateTest>>selectorsToBeIgnored (in category 'Coverage') -----
selectorsToBeIgnored

	 | deprecated private special |
	deprecated := #().
	private := #().
	special := #( #< #= #new #next #previous #printOn: #printOn:format: #storeOn: #fromString: ).

	^ super selectorsToBeIgnored, deprecated, private, special!

----- Method: DateTest>>setUp (in category 'Running') -----
setUp

	date := self dateClass newDay: 153 year: 1973.	"2 June 1973"

	aDate := Date readFrom: '01-23-2004' readStream.
	aTime := Time readFrom: '12:34:56 pm' readStream!

----- Method: DateTest>>testAccessing (in category 'Tests') -----
testAccessing

	self	
		assert: date day = 153;
		assert: date julianDayNumber = 2441836;
		assert: date leap = 0;
		assert: date monthIndex = 6;
		assert: date monthName = #June;
		assert: date weekday = #Saturday;
		assert: date weekdayIndex = 7;
		assert: date year = 1973.
!

----- Method: DateTest>>testAddDays (in category 'testing') -----
testAddDays
	self assert: (aDate addDays: 00) yyyymmdd =  '2004-01-23'.	
	self assert: (aDate addDays: 30) yyyymmdd =  '2004-02-22'.
	self assert: (aDate addDays: 60) yyyymmdd =  '2004-03-23'.
	self assert: (aDate addDays: 90) yyyymmdd =  '2004-04-22'.
	self assert: (aDate addDays:120) yyyymmdd =  '2004-05-22'!

----- Method: DateTest>>testAddMonths (in category 'testing') -----
testAddMonths
	self assert: (aDate addMonths: 0) yyyymmdd =  '2004-01-23'.	
	self assert: (aDate addMonths: 1) yyyymmdd =  '2004-02-23'.
	self assert: (aDate addMonths: 2) yyyymmdd =  '2004-03-23'.
	self assert: (aDate addMonths: 3) yyyymmdd =  '2004-04-23'.
	self assert: (aDate addMonths: 12) yyyymmdd =  '2005-01-23'.
	
	self assert: ((Date readFrom: '05-31-2017' readStream) addMonths: 1) yyyymmdd =  '2017-06-30'.
	self assert: ((Date readFrom: '02-29-2000' readStream) addMonths: 12) yyyymmdd =  '2001-02-28'!

----- Method: DateTest>>testArithmetic (in category 'Tests') -----
testArithmetic
	| d |
	d := date addDays: 32.		"4 July 1973"

	self 
		assert: d year = 1973;
		assert: d monthIndex = 7;
		assert: d dayOfMonth = 4.
	self 
		assert: (d subtractDate: date) = 32;
		assert: (date subtractDate: d) = -32.
	self	 
		assert: (d subtractDays: 32) = date.
!

----- Method: DateTest>>testAsDate (in category 'testing') -----
testAsDate
	self assert: (aDate asDate) = aDate
!

----- Method: DateTest>>testAsSeconds (in category 'testing') -----
testAsSeconds
	self assert: (aDate asSeconds) =   3252268800.
	self assert: (aDate asSeconds) =  ((103*365*24*60*60) + (22+25"leap days"*24*60*60)) .
	self assert: aDate  =  (Date fromSeconds: 3252268800).!

----- Method: DateTest>>testComparing (in category 'Tests') -----
testComparing
	| d1 d2 d3 |
	d1 := self dateClass newDay: 2 month: #June year: 1973.
	d2 := self dateClass newDay: 97 year: 2003. 		"7 April 2003"
	d3 := self dateClass newDay: 250 year: 1865. 		"7 September 1865"

	self
		assert: date = d1;
		assert: date = date copy;
		assert: date hash = d1 hash.
	self 
		assert: date < d2;
		deny: date < d3.
!

----- Method: DateTest>>testConverting (in category 'Tests') -----
testConverting

	self 
		assert: date asDate = date;
		assert: '2 June 1973' asDate = date;
		assert: date asSeconds = 2285280000.

	date dayMonthYearDo: [ :d :m :y | self assert: d = 2; assert: m = 6; assert: y = 1973 ].!

----- Method: DateTest>>testConvertingFromIso8601 (in category 'Tests') -----
testConvertingFromIso8601

	self 
		assert: '1973-06-02' asDate = date;
		assert: '1973-JUN-02' asDate = date;
		assert: '1973-June-02' asDate = date!

----- Method: DateTest>>testDateAndTimeNow (in category 'testing') -----
testDateAndTimeNow
	"Not a great test: could falsely fail if midnight come in between the two executions and doesnt catch time errors"
	self assert: Date dateAndTimeNow first  = Date today 
!

----- Method: DateTest>>testDayMonthYearDo (in category 'testing') -----
testDayMonthYearDo
	self assert: (aDate dayMonthYearDo: [:day :month :year | day asString , month asString, year asString]) = '2312004'
!

----- Method: DateTest>>testDaysInMonthForYear (in category 'testing') -----
testDaysInMonthForYear
	self assert: (Date daysInMonth: 'February' forYear: 2008)  = 29.	
	self assert: (Date daysInMonth: 'February' forYear: 2000)  = 29.	
	self assert: (Date daysInMonth: 'February' forYear: 2100)  = 28.	
	self assert: (Date daysInMonth: 'July' forYear: 2100)  = 31.	!

----- Method: DateTest>>testDaysInYear (in category 'testing') -----
testDaysInYear
	self assert: (Date daysInYear: 2008)  = 366.	
	self assert: (Date daysInYear: 2000)  = 366.	
	self assert: (Date daysInYear: 2100)  = 365	
!

----- Method: DateTest>>testDuration (in category 'testing') -----
testDuration
	self assert: aDate duration = 24 hours!

----- Method: DateTest>>testEqual (in category 'testing') -----
testEqual
	self assert: aDate = (Date readFrom: (ReadStream on: 'January 23, 2004')).!

----- Method: DateTest>>testFirstWeekdayOfMonthYear (in category 'testing') -----
testFirstWeekdayOfMonthYear
	self assert: (Date firstWeekdayOfMonth: 'January' year: 2004)  = 5.	
!

----- Method: DateTest>>testFromDays (in category 'Tests') -----
testFromDays
	| epoch d0 d1 d2 |
	epoch := self dateClass newDay: 1 year: 1901.
	d0 := self dateClass fromDays: 0. 			"1 January 1901"
	self assert: d0 = epoch.

	d1 := self dateClass fromDays:  26450. 	"2 June 1973"
	self assert: d1 = date.

	d2 := self dateClass fromDays: -100000.	"18 March 1627"
	self assert: d2 julianDayNumber = 2315386.

	self assert: aDate  =  (Date fromDays:  37642).
	self assert: aDate  =  (Date fromDays: 103*365 + 22 + 25 "leap days") .
	!

----- Method: DateTest>>testFromSeconds (in category 'Tests') -----
testFromSeconds
	| d |
	d := self dateClass fromSeconds: 2285280000. 
	self
		assert: d = date.
!

----- Method: DateTest>>testGeneralInquiries (in category 'Tests') -----
testGeneralInquiries

	| shuffled indices names now | 

	shuffled := #(#January #February #March #April #May #June #July 
					#August #September #October #November #December) shuffled.
	indices := shuffled collect: [ :m | self dateClass indexOfMonth: m ].
	names := indices collect: [ :i | self dateClass nameOfMonth: i ].
	self assert: names = shuffled.

	shuffled := #(#Monday #Tuesday #Wednesday #Thursday #Friday #Saturday #Sunday) shuffled.
	indices := shuffled collect: [ :m | self dateClass dayOfWeek: m ].
	names := indices collect: [ :i | self dateClass nameOfDay: i ].
	self assert: names = shuffled.
	
	now  := self dateClass dateAndTimeNow.
	self 
		assert: now size = 2;
		assert: now first = self dateClass today.

	self assert: (self dateClass firstWeekdayOfMonth: #June year: 1973) = 6.

	self
		assert: (self dateClass leapYear: 1973) = 0;
		assert: (self dateClass leapYear: 1972) = 1;
		assert: (self dateClass daysInYear: 1973) = 365;
		assert: (self dateClass daysInYear: 1972) = 366;
		assert: (self dateClass daysInMonth: #February forYear: 1973) = 28;
		assert: (self dateClass daysInMonth: #February forYear: 1972) = 29.
!

----- Method: DateTest>>testIndexOfMonth (in category 'testing') -----
testIndexOfMonth
	self assert: (Date indexOfMonth: 'January')  = 1.	
	self assert: (Date indexOfMonth: 'December')  = 12.	!

----- Method: DateTest>>testInitialization (in category 'Tests') -----
testInitialization

	self should: [ self dateClass initialize. true ].
!

----- Method: DateTest>>testInquiries (in category 'Tests') -----
testInquiries

	self	
		assert: date dayOfMonth = 2;
		assert: date dayOfYear = 153;
		assert: date daysInMonth = 30;
		assert: date daysInYear = 365;
		assert: date daysLeftInYear = (365 - 153);
		assert: date firstDayOfMonth = 152.
!

----- Method: DateTest>>testJulianDayNumber (in category 'testing') -----
testJulianDayNumber
	self assert: aDate = (Date julianDayNumber: ((4713+2004)*365 +1323) ).  !

----- Method: DateTest>>testLeap (in category 'testing') -----
testLeap
	self assert: aDate leap = 1.	

!

----- Method: DateTest>>testLeapNot (in category 'testing') -----
testLeapNot
	self assert: (aDate addDays: 365) leap = 0
!

----- Method: DateTest>>testLessThan (in category 'testing') -----
testLessThan
	self assert: aDate < (Date readFrom: (ReadStream on: '01-24-2004')).!

----- Method: DateTest>>testMakeUTC (in category 'testing') -----
testMakeUTC
	"Equal dates should compare equal regardless of which TimeZone
	they are created in."
	| priorTz march31stLocal march31stOcean |
	"This test won't work in GMT-9, but nobody lives there."
	self deny: DateAndTime localTimeZone offset hours = -9.
	priorTz := DateAndTime localTimeZone.
	march31stLocal := Date today.
	DateAndTime
		localTimeZone: (TimeZone
				offset: -9 hours
				name: 'No Countries'
				abbreviation: 'Ocean').
	march31stOcean := Date today.
	DateAndTime localTimeZone: priorTz.
	self assert: march31stLocal makeUTC = march31stOcean makeUTC ;
		 deny: march31stOcean makeUTC > march31stLocal makeUTC ;
		 deny: march31stOcean makeUTC < march31stLocal makeUTC!

----- Method: DateTest>>testMmddyyyy (in category 'testing') -----
testMmddyyyy
	self assert: aDate mmddyyyy =  '1/23/2004'!

----- Method: DateTest>>testNameOfMonth (in category 'testing') -----
testNameOfMonth
	self assert: (Date nameOfMonth: 5) = 'May'.	
	self assert: (Date nameOfMonth: 8) = 'August' !

----- Method: DateTest>>testNew (in category 'Tests') -----
testNew
	| epoch |
	epoch := self dateClass newDay: 1 year: 1901.
	self assert: (self dateClass new = epoch).!

----- Method: DateTest>>testNewDayMonthYear (in category 'testing') -----
testNewDayMonthYear
	self assert: aDate = (Date newDay: 23 month: 1 year: 2004)	
!

----- Method: DateTest>>testNewDayYear (in category 'testing') -----
testNewDayYear
	self assert: aDate = (Date newDay: 23 year: 2004)	
!

----- Method: DateTest>>testPreviousFriday (in category 'testing') -----
testPreviousFriday
	self assert: (aDate previous: 'Friday') yyyymmdd = '2004-01-16'

!

----- Method: DateTest>>testPreviousNext (in category 'Tests') -----
testPreviousNext
	| n p pt ps |
	n := date next.
	p := date previous.

	self
		assert: n year = 1973;
		assert: n dayOfYear = 154;
		assert: p year = 1973;
		assert: p dayOfYear = 152.

	pt := date previous: #Thursday.		"31 May 1973"
	self	
		assert: pt year = 1973;
		assert: pt dayOfYear = 151.

	ps := date previous: #Saturday.		" 26 May 1973"
	self	
		assert: ps year = 1973;
		assert: ps dayOfYear = (153-7).
!

----- Method: DateTest>>testPreviousThursday (in category 'testing') -----
testPreviousThursday
	self assert: (aDate previous: 'Thursday') yyyymmdd = '2004-01-22'

!

----- Method: DateTest>>testPrintFormat (in category 'testing') -----
testPrintFormat
	self assert: (aDate printFormat: #(1 2 3 $? 2 2)) =  '23?Jan?04'!

----- Method: DateTest>>testPrintOn (in category 'testing') -----
testPrintOn
	| ref ws |
	ref := '23 January 2004'.
	ws := '' writeStream.
	aDate printOn: ws.
	self assert: ws contents = ref!

----- Method: DateTest>>testPrintOnFormat (in category 'testing') -----
testPrintOnFormat
	| ref ws |
	ref :='04*Jan*23'.
	ws := '' writeStream.
	aDate printOn: ws format: #(3 2 1 $* 2 2).
	self assert: ws contents = ref!

----- Method: DateTest>>testPrinting (in category 'Tests') -----
testPrinting

	self	
		assert: date mmddyyyy = '6/2/1973';
		assert: date yyyymmdd = '1973-06-02';
		assert: (date printFormat: #(3 1 2 $!! 2 1 1)) = '1973!!2!!Jun'.
!

----- Method: DateTest>>testReadFrom (in category 'Tests') -----
testReadFrom
	| s1 s2 s3 s4 s5 | 
	s1 := '2 June 1973'.
	s2 := '2-JUN-73'.
	s3 := 'June 2, 1973'.
	s4 := '6/2/73'.
	s5 := '2JUN73'.

	self	
		assert: date = (self dateClass readFrom: s1 readStream);
		assert: date = (self dateClass readFrom: s2 readStream);
		assert: date = (self dateClass readFrom: s3 readStream);
		assert: date = (self dateClass readFrom: s4 readStream);
		assert: date = (self dateClass readFrom: s5 readStream).!

----- Method: DateTest>>testStarting (in category 'testing') -----
testStarting
	self assert: aDate = (Date starting: ((DateAndTime fromString: '2004-01-23T12:12') offset: Date defaultOffset))!

----- Method: DateTest>>testStoreOn (in category 'testing') -----
testStoreOn
	| ref ws |
	ref := '''23 January 2004'' asDate'.
	ws := '' writeStream.
	aDate storeOn: ws.
	self assert: ws contents = ref!

----- Method: DateTest>>testStoring (in category 'Tests') -----
testStoring

	self	
		assert: date storeString = '''2 June 1973'' asDate';
		assert: date = ('2 June 1973' asDate).
!

----- Method: DateTest>>testSubtractDate (in category 'testing') -----
testSubtractDate
	self assert: (aDate subtractDate:(aDate addDays: 30)) = -30.	
	self assert: (aDate subtractDate:(aDate subtractDays: 00)) = 0.	
	self assert: (aDate subtractDate:(aDate subtractDays: 30)) = 30.

!

----- Method: DateTest>>testSubtractDays (in category 'testing') -----
testSubtractDays
	self assert: (aDate subtractDays: 00) yyyymmdd =  '2004-01-23'.	
	self assert: (aDate subtractDays: 30) yyyymmdd =  '2003-12-24'.
	self assert: (aDate subtractDays: 60) yyyymmdd =  '2003-11-24'
!

----- Method: DateTest>>testTomorrow (in category 'testing') -----
testTomorrow
	"Not a great test: could falsely fail if midnight come in between the two executions and doesnt catch many errors"
	self assert: Date tomorrow  > Date today 
!

----- Method: DateTest>>testWeekday (in category 'testing') -----
testWeekday
	self assert: aDate weekday = 'Friday'.	
	self assert: aDate weekdayIndex = 6. 
	self assert: (Date dayOfWeek: aDate weekday ) =6.
	self assert: (Date nameOfDay: 6 ) = 'Friday'	!

----- Method: DateTest>>testYesterday (in category 'testing') -----
testYesterday
	"Not a great test:  doesnt catch many errors"
	self assert: Date yesterday  < Date today 
!

----- Method: DateTest>>testYyyymmdd (in category 'testing') -----
testYyyymmdd
	self assert: aDate yyyymmdd =  '2004-01-23'!

ClassTestCase subclass: #DurationTest
	instanceVariableNames: 'aDuration'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Chronology-Tests'!

----- Method: DurationTest>>classToBeTested (in category 'Coverage') -----
classToBeTested

	^ Duration


!

----- Method: DurationTest>>selectorsToBeIgnored (in category 'Coverage') -----
selectorsToBeIgnored

	| private | 
	private := #( #printOn: ).

	^ super selectorsToBeIgnored, private
!

----- Method: DurationTest>>setUp (in category 'running') -----
setUp
	aDuration := Duration days: 1 hours: 2 minutes: 3 seconds: 4 nanoSeconds: 5 !

----- Method: DurationTest>>testAbs (in category 'testing') -----
testAbs
	self assert: aDuration abs = aDuration. 
	self assert: (Duration nanoSeconds: -5)  abs =  (Duration nanoSeconds: 5). 
!

----- Method: DurationTest>>testAgo (in category 'testing') -----
testAgo
	self assert: ((10 minutes ago) isMemberOf: DateAndTime).
	self assert: ((10 weeks ago) < DateAndTime now).
	self assert: ((-50 seconds ago) > DateAndTime now).
	self assert: ((10 hours ago) < DateAndTime now).
	self assert: (0 seconds ago - DateAndTime now < 1 second).!

----- Method: DurationTest>>testAsDelay (in category 'testing') -----
testAsDelay
	self deny: aDuration asDelay =   aDuration.
	"want to come up with a more meaningful test"
!

----- Method: DurationTest>>testAsDuration (in category 'testing') -----
testAsDuration
	self assert: aDuration asDuration =  aDuration
	
!

----- Method: DurationTest>>testAsMilliSeconds (in category 'testing') -----
testAsMilliSeconds
	self assert: (Duration nanoSeconds: 1000000) asMilliSeconds = 1.
	self assert: (Duration seconds: 1) asMilliSeconds = 1000.
	self assert: (Duration nanoSeconds: 1000000) asMilliSeconds = 1.
	self assert: (Duration nanoSeconds: 1000000) asMilliSeconds = 1.
	self assert: aDuration asMilliSeconds = 93784000.
	self assert: (Duration milliSeconds: 3775) asSeconds = 3.
	self assert: (Duration milliSeconds: 3775) nanoSeconds = 775000000!

----- Method: DurationTest>>testAsNanoSeconds (in category 'testing') -----
testAsNanoSeconds
	self assert: (Duration nanoSeconds: 1)  asNanoSeconds = 1.
	self assert: (Duration seconds: 1)  asNanoSeconds = 1000000000.	
	self assert: aDuration   asNanoSeconds = 93784000000005.!

----- Method: DurationTest>>testAsSeconds (in category 'testing') -----
testAsSeconds
	self assert: (Duration nanoSeconds: 1000000000)  asSeconds = 1.
	self assert: (Duration seconds: 1)  asSeconds = 1.	
	self assert: aDuration   asSeconds = 93784.!

----- Method: DurationTest>>testComparing (in category 'Tests') -----
testComparing

	| d1 d2 d3 |
	d1 := Duration seconds: 10 nanoSeconds: 1.
	d2 := Duration seconds: 10 nanoSeconds: 1.
	d3 := Duration seconds: 10 nanoSeconds: 2.
	
	self
		assert: (d1 = d1);
		assert: (d1 = d2);
		deny: (d1 = d3);
		assert: (d1 < d3)
!

----- Method: DurationTest>>testDays (in category 'testing') -----
testDays
	self assert: aDuration   days = 1.
	self assert: (Duration   days: 1) days= 1.	!

----- Method: DurationTest>>testDivide (in category 'testing') -----
testDivide
	self assert: aDuration / aDuration = 1. 
	self assert: aDuration / 2 = (Duration days: 0 hours: 13 minutes: 1 seconds: 32 nanoSeconds: 2). 
	self assert: aDuration / (1/2) = (Duration days: 2 hours: 4 minutes: 6 seconds: 8 nanoSeconds: 10).
!

----- Method: DurationTest>>testFromNow (in category 'testing') -----
testFromNow

	self assert: ((10 seconds fromNow) > DateAndTime now).
	self assert: ((0 days fromNow - DateAndTime now) < 1 second).
	self assert: ((-1 weeks fromNow) < DateAndTime now).
	self assert: ((1000 milliSeconds fromNow) isMemberOf: DateAndTime).
	self assert: ((250 hours fromNow) > DateAndTime now).
	self assert: ((-50 minutes fromNow) < DateAndTime now).!

----- Method: DurationTest>>testFromString (in category 'testing') -----
testFromString
	self assert: aDuration = (Duration fromString: '1:02:03:04.000000005').
!

----- Method: DurationTest>>testHash (in category 'testing') -----
testHash
	self assert: aDuration hash =    	(Duration days: 1 hours: 2 minutes: 3 seconds: 4 nanoSeconds: 5) hash.
	self assert: aDuration hash =     93789
	"must be a more meaningful test?"!

----- Method: DurationTest>>testHours (in category 'testing') -----
testHours
	self assert: aDuration   hours = 2.
	self assert: (Duration   hours: 2) hours = 2.	!

----- Method: DurationTest>>testIntegerDivision (in category 'testing') -----
testIntegerDivision
	self assert: aDuration // aDuration = 1. 
	self assert: aDuration // 2 =  (aDuration / 2). 
	"is there ever a case where this is not true, since precision is always to the nano second?"!

----- Method: DurationTest>>testLessThan (in category 'testing') -----
testLessThan
	self assert: aDuration  < (aDuration + 1 day ).
	self deny: aDuration < aDuration.
	!

----- Method: DurationTest>>testMilliSeconds (in category 'testing') -----
testMilliSeconds

	#(
		"argument (milliseconds)	seconds	nanoseconds"
		(5							0			5000000)
		(1005						1			5000000)
		(-5							0			-5000000)
		(-1005						-1			-5000000)
		(1234567					1234		567000000)
		(-1234567					-1234		-567000000)		
	) do: [ :each |
		| duration |
		duration := Duration milliSeconds: each first.
		self assert: duration asSeconds = each second.
		self assert: duration nanoSeconds = each third ]!

----- Method: DurationTest>>testMinus (in category 'testing') -----
testMinus
	self assert: aDuration - aDuration = (Duration seconds: 0).
	self assert: aDuration - (Duration days: -1 hours: -2 minutes: -3 seconds: -4 nanoSeconds: -5) = 
						    (Duration days: 2  hours: 4  minutes: 6  seconds: 8  nanoSeconds: 10). 
	self assert: aDuration - (Duration days: 0  hours: 1  minutes: 2  seconds: 3  nanoSeconds: 4) = 
						    (Duration days: 1  hours: 1  minutes: 1  seconds: 1  nanoSeconds: 1). 
	self assert: aDuration - (Duration days: 0  hours: 3   minutes: 0  seconds: 5  nanoSeconds: 0) = 
						    (Duration days: 0  hours: 23  minutes: 2  seconds: 59  nanoSeconds: 5). !

----- Method: DurationTest>>testMinutes (in category 'testing') -----
testMinutes
	self assert: aDuration   minutes = 3.
	self assert: (Duration minutes: 3) minutes = 3.	!

----- Method: DurationTest>>testModulo (in category 'Tests') -----
testModulo

	| d1 d2 d3 |
	d1 := 11.5 seconds.
	d2 := d1 \\ 3.
	self assert: d2 = (Duration nanoSeconds: 1).

	d3 := d1 \\ (3 seconds).
	self assert: d3 =  (Duration seconds: 2 nanoSeconds: 500000000).

	self assert: aDuration \\ aDuration = 
		(Duration days: 0 hours: 0 minutes: 0 seconds: 0 nanoSeconds: 0). 
	self assert: aDuration \\ 2 = 
		(Duration days: 0 hours: 0 minutes: 0 seconds: 0 nanoSeconds: 1).
	

!

----- Method: DurationTest>>testMonthDurations (in category 'Tests') -----
testMonthDurations

	| jan feb dec |
	jan := Duration month: #January.
	feb := Duration month: #February.
	dec := Duration month: #December.
	
	self 
		assert: jan = (Year current months first duration);
		assert: feb = (Year current months second duration);
		assert: dec = (Year current months last duration)

		
!

----- Method: DurationTest>>testMultiply (in category 'testing') -----
testMultiply
	self assert: aDuration * 2 = (Duration days: 2 hours: 4 minutes: 6 seconds: 8 nanoSeconds: 10). !

----- Method: DurationTest>>testNanoSeconds (in category 'testing') -----
testNanoSeconds
	self assert: aDuration nanoSeconds = 5.
	self assert: (Duration nanoSeconds: 5) nanoSeconds = 5.	!

----- Method: DurationTest>>testNegated (in category 'testing') -----
testNegated
	self assert: aDuration + aDuration negated = (Duration seconds: 0). 
!

----- Method: DurationTest>>testNegative (in category 'testing') -----
testNegative
	self deny: aDuration negative.
	self assert: aDuration negated negative
!

----- Method: DurationTest>>testNew (in category 'testing') -----
testNew
	"self assert: Duration new =  (Duration seconds: 0)."
    "new is not valid as a creation method: MessageNotUnderstood: UndefinedObject>>quo:, where Duration seconds is nil"!

----- Method: DurationTest>>testNormalizeNanoSeconds (in category 'testing') -----
testNormalizeNanoSeconds
	"Subtraction of two DateAndTime values may result in a request to
	create a Duration with negative nanoseconds and positive seconds.
	The resulting Duration should be normalized, otherwise its printString
	will be invalid."

	| d t1 t2 |
	t1 := '2004-01-07T11:55:01+00:00' asDateAndTime. 
	t2 := '2004-01-07T11:55:00.9+00:00' asDateAndTime.
	d := t1 - t2. "100 millisecond difference"
	self assert: d nanoSeconds > 0.
	self assert: d seconds = 0.
	self assert: d nanoSeconds = 100000000.
	self assert: d asString = '0:00:00:00.1'.
	"Verify that other combinations produces reasonable printString values"
	self assert: (Duration seconds: 1 nanoSeconds: 100000000) printString = '0:00:00:01.1'.
	self assert: (Duration seconds: -1 nanoSeconds: -100000000) printString = '-0:00:00:01.1'.
	self assert: (Duration seconds: 1 nanoSeconds: -100000000) printString = '0:00:00:00.9'.
	self assert: (Duration seconds: -1 nanoSeconds: 100000000) printString = '-0:00:00:00.9'
!

----- Method: DurationTest>>testNumberConvenienceMethods (in category 'Tests') -----
testNumberConvenienceMethods

	self
		assert: 1 week = (Duration days: 7);
		assert: -1 week = (Duration days: -7);
		assert: 1 day = (Duration days: 1);
		assert: -1 day = (Duration days: -1);
		assert: 1 hours = (Duration hours: 1);
		assert: -1 hour = (Duration hours: -1);
		assert: 1 minute = (Duration seconds: 60);
		assert: -1 minute = (Duration seconds: -60);
		assert: 1 second = (Duration seconds: 1);
		assert: -1 second = (Duration seconds: -1);
		assert: 1 milliSecond = (Duration milliSeconds: 1);
		assert: -1 milliSecond = (Duration milliSeconds: -1);
		assert: 1 nanoSecond = (Duration nanoSeconds: 1);
		assert: -1 nanoSecond = (Duration nanoSeconds: -1)
		!

----- Method: DurationTest>>testPlus (in category 'testing') -----
testPlus
	self assert: (aDuration + 0 hours) = aDuration.
	self assert: (aDuration + aDuration) = (Duration days: 2 hours: 4 minutes: 6 seconds: 8 nanoSeconds: 10). !

----- Method: DurationTest>>testPositive (in category 'testing') -----
testPositive
	self assert: (Duration nanoSeconds: 0) positive.
	self assert: aDuration positive.
	self deny: aDuration negated positive
!

----- Method: DurationTest>>testPrintOn (in category 'testing') -----
testPrintOn
	| ref ws |
	ref := '1:02:03:04.000000005'.
	ws := '' writeStream.
	aDuration printOn: ws.
	self assert: ws contents = ref!

----- Method: DurationTest>>testQuotient (in category 'Tests') -----
testQuotient

	| d1 d2 q |
	d1 := 11.5 seconds.
	d2 := d1 // 3.
	self assert: d2 = (Duration seconds: 3 nanoSeconds: 833333333).

	q := d1 // (3 seconds).
	self assert: q = 3.

!

----- Method: DurationTest>>testReadFrom (in category 'testing') -----
testReadFrom
	self assert: aDuration =  (Duration readFrom: (ReadStream on: '1:02:03:04.000000005'))
!

----- Method: DurationTest>>testReadFromTrailingDigits (in category 'Tests') -----
testReadFromTrailingDigits
	"http://bugs.squeak.org/view.php?id=6764"
	self should:  (Duration readFrom: '0:00:00:00.001 ' readStream) nanoSeconds = 1000000.!

----- Method: DurationTest>>testRoundTo (in category 'Tests') -----
testRoundTo

	self assert: ((5 minutes + 37 seconds) roundTo: (2 minutes)) = (6 minutes).
	
	self assert:  (aDuration roundTo: (Duration days: 1)) =
	               (Duration days: 1 hours: 0 minutes: 0 seconds: 0 nanoSeconds: 0).
	self assert:  (aDuration roundTo: (Duration hours: 1)) =
	               (Duration days: 1 hours: 2 minutes: 0 seconds: 0 nanoSeconds: 0).	
	self assert:  (aDuration roundTo: (Duration minutes: 1)) =
	               (Duration days: 1 hours: 2 minutes: 3 seconds: 0 nanoSeconds: 0).!

----- Method: DurationTest>>testSeconds (in category 'testing') -----
testSeconds
	self assert: aDuration seconds =   4.
	self assert: (Duration  nanoSeconds: 2) seconds = 0.
	self assert: (Duration nanoSeconds: 999999999) seconds = 0.
	self assert: (Duration nanoSeconds: 1000000001) seconds = 1.
	self assert: (Duration  seconds: 2) seconds = 2.	
	self assert: (Duration  days: 1 hours: 2 minutes: 3 seconds:4) seconds = 4.
	self deny: (Duration  days: 1 hours: 2 minutes: 3 seconds:4) seconds = (1*24*60*60+(2*60*60)+(3*60)+4).	!

----- Method: DurationTest>>testSecondsNanoSeconds (in category 'testing') -----
testSecondsNanoSeconds 
	self assert: (Duration   seconds: 0 nanoSeconds: 5)  = (Duration  nanoSeconds: 5).	
	"not sure I should include in sunit since its Private "
	self assert: (aDuration seconds: 0 nanoSeconds: 1) = (Duration nanoSeconds: 1). 
!

----- Method: DurationTest>>testStoreOn (in category 'testing') -----
testStoreOn
     self assert: (aDuration storeOn: (WriteStream on:'')) asString ='1:02:03:04.000000005'. 
     "storeOn: returns a duration (self) not a stream"!

----- Method: DurationTest>>testTicks (in category 'testing') -----
testTicks
	self assert: aDuration ticks =  #(1 7384 5)!

----- Method: DurationTest>>testTruncateTo (in category 'Tests') -----
testTruncateTo

	self assert: ((5 minutes + 37 seconds) truncateTo: (2 minutes)) = (4 minutes).
	self assert:  (aDuration truncateTo: (Duration days: 1)) =
	               (Duration days: 1 hours: 0 minutes: 0 seconds: 0 nanoSeconds: 0).
	self assert:  (aDuration truncateTo: (Duration hours: 1)) =
	               (Duration days: 1 hours: 2 minutes: 0 seconds: 0 nanoSeconds: 0).	
	self assert:  (aDuration truncateTo: (Duration minutes: 1)) =
	               (Duration days: 1 hours: 2 minutes: 3 seconds: 0 nanoSeconds: 0).!

----- Method: DurationTest>>testWeeks (in category 'testing') -----
testWeeks
	self assert: (Duration  weeks: 1) days= 7.	!

----- Method: DurationTest>>testZero (in category 'testing') -----
testZero
	self assert: (Duration zero) = (Duration seconds: 0).	!

ClassTestCase subclass: #MonthTest
	instanceVariableNames: 'month'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Chronology-Tests'!

!MonthTest commentStamp: 'brp 7/26/2003 22:44' prior: 0!
This is the unit test for the class Month.
!

----- Method: MonthTest>>classToBeTested (in category 'Coverage') -----
classToBeTested

	^ Month!

----- Method: MonthTest>>selectorsToBeIgnored (in category 'Coverage') -----
selectorsToBeIgnored

	| deprecated private special |
	deprecated := #().
	private := #( #printOn: ).
	special := #( #next ).

	^ super selectorsToBeIgnored, deprecated, private, special.!

----- Method: MonthTest>>setUp (in category 'Running') -----
setUp

	super setUp.
	month := Month month: 7 year: 1998.!

----- Method: MonthTest>>tearDown (in category 'Running') -----
tearDown

	super tearDown.
	month := nil.!

----- Method: MonthTest>>testConverting (in category 'Tests') -----
testConverting

	self assert: month asDate = '1 July 1998' asDate!

----- Method: MonthTest>>testEnumerating (in category 'Tests') -----
testEnumerating
	| weeks |
	weeks := OrderedCollection new.
	month weeksDo: [ :w | weeks add: w start ].
	0 to: 4 do: [ :i | weeks remove: (Week starting:  ('29 June 1998' asDate addDays: i * 7)) start ].
	self assert: weeks isEmpty!

----- Method: MonthTest>>testIndexOfMonth (in category 'Tests') -----
testIndexOfMonth

	| m |
	m := #(#January #February #March #April #May #June #July #August #September #October #November #December).
	
	m withIndexDo: [:item :index | self assert: (Month indexOfMonth: item) = index].
	
	self should: [Month indexOfMonth: 1] raise: TestResult error.
	self should: [Month indexOfMonth: #'1'] raise: TestResult error.
	self should: [Month indexOfMonth: #Marsh] raise: TestResult error. "notice the misspell!!"
	self should: [Month indexOfMonth: #UnexistingMonth] raise: TestResult error.!

----- Method: MonthTest>>testInquiries (in category 'Tests') -----
testInquiries

	self 
		assert: month index = 7;
		assert: month name = #July;
		assert: month duration = (31 days).
!

----- Method: MonthTest>>testInstanceCreation (in category 'Tests') -----
testInstanceCreation
	| m1 m2 |
	m1 := Month starting:  '4 July 1998' asDate.
	m2 := Month month: #July year: 1998.
	self
		assert: month = m1;
		assert: month = m2!

----- Method: MonthTest>>testNameOfMonth (in category 'Tests') -----
testNameOfMonth

	| m |
	m := #(#January #February #March #April #May #June #July #August #September #October #November #December).
	
	m withIndexDo: [:item :index | self assert: (Month nameOfMonth: index) = item].
	
	self should: [Month nameOfMonth: 0] raise: TestResult error.
	self should: [Month nameOfMonth: 13] raise: TestResult error.
	self should: [Month nameOfMonth: #January] raise: TestResult error.!

----- Method: MonthTest>>testPreviousNext (in category 'Tests') -----
testPreviousNext
	| n p |
	n := month next.
	p := month previous.

	self
		assert: n year = 1998;
		assert: n index = 8;
		assert: p year = 1998;
		assert: p index = 6.

!

----- Method: MonthTest>>testPrinting (in category 'Tests') -----
testPrinting

	self 
		assert: month printString = 'July 1998'.
!

----- Method: MonthTest>>testReadFrom (in category 'Tests') -----
testReadFrom

	| m |
	m := Month readFrom: 'July 1998' readStream.
	self 
		assert: m = month!

ClassTestCase subclass: #ScheduleTest
	instanceVariableNames: 'firstEvent aSchedule restoredTimeZone'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Chronology-Tests'!

----- Method: ScheduleTest>>classToBeTested (in category 'Coverage') -----
classToBeTested

	^ Schedule

!

----- Method: ScheduleTest>>selectorsToBeIgnored (in category 'Coverage') -----
selectorsToBeIgnored

	| private | 
	private := #( #printOn: ).

	^ super selectorsToBeIgnored, private
!

----- Method: ScheduleTest>>setUp (in category 'running') -----
setUp
 	 "Schedule is a type of Timespan representing repeated occurences of the same event. 
	The beginning of the schedule is the first occurrence of the event.
	A schedule maintains an array of Durations. 
	Each durations specify the offset to the next scheduled each. 
	The duration of each occurence of the event is not specified. 
	Nor are any other attributes such as name"

	restoredTimeZone := DateAndTime localTimeZone.
	DateAndTime localTimeZone: (TimeZone timeZones detect: [:tz | tz abbreviation = 'GMT']).

	"Create aSchedule with an event scheduled for 8:30pm every Saturday 
	and Sunday for the year 2003. "
	"Create the first event occurring on the first Saturday at 8:30 pm: 1/4/03"
	firstEvent :=  DateAndTime year: 2003 month: 1 day: 4 hour: 20 minute: 30. 
	
	"Create a schedule for one year starting with the first event" 
	aSchedule := Schedule starting: firstEvent duration: 52 weeks.

	"Schedule the recurring events by scheduling the time in between each one.  
	One day for Sat-Sun. 6 days for Sun-Sat" 
	aSchedule schedule: { Duration days: 1. Duration days: 6 }.
!

----- Method: ScheduleTest>>tearDown (in category 'running') -----
tearDown

	DateAndTime localTimeZone: restoredTimeZone.
!

----- Method: ScheduleTest>>testBetweenAndDoDisjointWithSchedule (in category 'testing') -----
testBetweenAndDoDisjointWithSchedule
	| count |
	count := 0.
	aSchedule
		between: (DateAndTime
				year: 2004
				month: 4
				day: 1)
		and: (DateAndTime
				year: 2004
				month: 4
				day: 30)
		do: [:each | count := count + 1].
	self assert: count = 0!

----- Method: ScheduleTest>>testBetweenAndDoIncludedInSchedule (in category 'testing') -----
testBetweenAndDoIncludedInSchedule
	| count |
	count := 0.
	aSchedule
		between: (DateAndTime
				year: 2003
				month: 4
				day: 1)
		and: (DateAndTime
				year: 2003
				month: 4
				day: 30)
		do: [:each | count := count + 1].
	self assert: count = 8!

----- Method: ScheduleTest>>testBetweenAndDoOverlappingSchedule (in category 'testing') -----
testBetweenAndDoOverlappingSchedule
	| count |
	count := 0.
	aSchedule
		between: (DateAndTime
				year: 2002
				month: 12
				day: 1)
		and: (DateAndTime
				year: 2003
				month: 1
				day: 31)
		do: [:each | count := count + 1].
	self assert: count = 8!

----- Method: ScheduleTest>>testDateAndTimes (in category 'testing') -----
testDateAndTimes
	| answer |
	self assert: aSchedule dateAndTimes size  = 104.
	self assert: aSchedule dateAndTimes first = firstEvent.
	answer := true.
	aSchedule dateAndTimes do: [:each | (each dayOfWeekName = 'Saturday'
		or: [each dayOfWeekName = 'Sunday']) ifFalse: [^false]].
	self assert: answer
!

----- Method: ScheduleTest>>testExampleFromSwikiPage (in category 'testing') -----
testExampleFromSwikiPage
	"It is often neccessary to schedule repeated events, like airline flight schedules, TV programmes, and file backups.
	 Schedule is a Timespan which maintains an array of Durations.
	 The durations specify the offset to the next scheduled DateAndTime. "
	"Consider a TV programme scheduled for 8:30pm every Saturday and Sunday for the current year. "
	"Find the first Saturday and set its time to 20h30"
	| sat shows |
	sat := Year current asMonth dates detect: [ :d | d dayOfWeekName = #Saturday ].
	sat := sat start + (Duration hours: 20.5).
	"Create a schedule" 
	shows := Schedule starting: sat ending: Year current end.
	shows schedule: { Duration days: 1. Duration days: 6 }.
	"To inspect:"
	shows dateAndTimes.
	shows dateAndTimes collect: [ :dt | dt dayOfWeekName ].

!

----- Method: ScheduleTest>>testFromDateAndTime (in category 'Tests') -----
testFromDateAndTime

	| oc1 oc2 |
	oc1 := OrderedCollection new.
	DateAndTime today to: DateAndTime tomorrow by: 10 hours do: [ :dt | oc1 add: dt ].

	oc2 := { DateAndTime today. 
			(DateAndTime today + 10 hours). 
				(DateAndTime today + 20 hours) }.

	self assert: (oc1 asArray = oc2)!

----- Method: ScheduleTest>>testIncludes (in category 'testing') -----
testIncludes
	self assert: (aSchedule includes: (DateAndTime year: 2003 month: 6 day: 15 hour: 20 minute: 30 second: 0 offset: 0 hours))
	
!

----- Method: ScheduleTest>>testMonotonicity (in category 'Tests') -----
testMonotonicity

	| t1 t2 t3 t4 |
	t1 := DateAndTime now.
	t2 := DateAndTime now.
	t3 := DateAndTime now.
	t4 := DateAndTime now.

	self 
		assert: (	t1 <= t2);
		assert: (	t2 <= t3);
		assert: (	t3 <= t4).
!

----- Method: ScheduleTest>>testSchedule (in category 'testing') -----
testSchedule
	self assert: aSchedule schedule size = 2.
	self assert: aSchedule schedule first = 1 days.	
	self assert: aSchedule schedule second = 6 days.
!

ClassTestCase subclass: #StopwatchTest
	instanceVariableNames: 'aStopwatch aDelay'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Chronology-Tests'!

----- Method: StopwatchTest>>classToBeTested (in category 'Coverage') -----
classToBeTested

	^ Stopwatch

!

----- Method: StopwatchTest>>selectorsToBeIgnored (in category 'Coverage') -----
selectorsToBeIgnored

	| private | 
	private := #( #printOn: #state: ).

	^ super selectorsToBeIgnored, private
!

----- Method: StopwatchTest>>setUp (in category 'running') -----
setUp
	aStopwatch := Stopwatch new.
	aDelay := Delay forMilliseconds: 1.!

----- Method: StopwatchTest>>testActive (in category 'Tests') -----
testActive

	| sw |
	sw := Stopwatch new.
	sw activate.
	
	1 seconds asDelay wait.
	self 
		assert: (sw duration >= 1 seconds).

	2 seconds asDelay wait.
	self 
		assert: (sw duration >= 3 seconds).

	sw suspend.!

----- Method: StopwatchTest>>testChangingStatus (in category 'testing') -----
testChangingStatus
	aStopwatch activate.
	self assert: aStopwatch isActive.
	self assert: aStopwatch timespans size = 1.
	aStopwatch suspend.
	self assert: aStopwatch isSuspended.
	self assert: aStopwatch timespans size = 1.
	aStopwatch activate.
	aStopwatch reActivate.
	self assert: aStopwatch isActive.
	self assert: aStopwatch timespans size = 3.
	aStopwatch reset.
	self assert: aStopwatch isSuspended.
	self assert: aStopwatch timespans size = 0.!

----- Method: StopwatchTest>>testInitialStatus (in category 'testing') -----
testInitialStatus
	self assert: aStopwatch isSuspended.
	self deny: aStopwatch isActive.
	self assert: aStopwatch duration = 0 seconds!

----- Method: StopwatchTest>>testMultipleTimings (in category 'testing') -----
testMultipleTimings
	aStopwatch activate.
	aDelay wait.
	aStopwatch suspend.
	aStopwatch activate.
	aDelay wait.
	aStopwatch suspend.
	self assert: aStopwatch timespans size = 2. 
	self assert: aStopwatch timespans first asDateAndTime <= 
					aStopwatch timespans last asDateAndTime.
!

----- Method: StopwatchTest>>testNew (in category 'Tests') -----
testNew

	| sw |
	sw := Stopwatch new.
	
	self 
		assert: (sw isSuspended);
		assert: (sw state = #suspended);
		deny: (sw isActive);
		assert: (sw timespans isEmpty)

!

----- Method: StopwatchTest>>testPrintOn (in category 'testing') -----
testPrintOn
	| ref ws |
	ref := 'a Stopwatch(suspended:0:00:00:00)'.
	ws := '' writeStream.
	aStopwatch printOn: ws.
	self assert: ws contents = ref!

----- Method: StopwatchTest>>testReActivate (in category 'Tests') -----
testReActivate

	| sw |
	sw := Stopwatch new.
	sw 
		activate;
		suspend;
		reActivate.
	
	self 
		assert: (sw isActive).
!

----- Method: StopwatchTest>>testReset (in category 'Tests') -----
testReset

	| sw |
	sw := Stopwatch new.
	sw activate.
	
	sw reset.
	self 
		assert: (sw isSuspended);
		assert: (sw timespans isEmpty)
!

----- Method: StopwatchTest>>testSingleTiming (in category 'testing') -----
testSingleTiming
	| timeBefore |
	timeBefore := DateAndTime now.
	aStopwatch activate.
	aDelay wait.
	aStopwatch suspend.
	self assert: aStopwatch timespans size = 1. 
	self assert: aStopwatch timespans first asDateAndTime >= timeBefore. 
	self assert: aStopwatch timespans first asDateAndTime <= aStopwatch end.
!

----- Method: StopwatchTest>>testStartStop (in category 'Tests') -----
testStartStop

	| sw t1 t2 t3 t4 |
	sw := Stopwatch new.
	t1 := DateAndTime now.
	(Delay forMilliseconds: 10) wait.
	sw activate; activate.
	(Delay forMilliseconds: 10) wait.
	t2 := DateAndTime now.
	
	self 
		deny: (sw isSuspended);
		assert: (sw isActive);
		assert: (sw timespans size = 1);
		assert: (t1 <= sw start);
		assert: (sw start <= t2).

	(Delay forMilliseconds: 10) wait.
	t3 := DateAndTime now.
	(Delay forMilliseconds: 10) wait.
	sw suspend; suspend.
	(Delay forMilliseconds: 10) wait.
	t4 := DateAndTime now.

	self 
		assert: (sw isSuspended);
		deny: (sw isActive);
		assert: (sw timespans size = 1);
		assert: (sw end between: t3 and: t4);
		assert: (t3 <= sw end);
		assert: (sw end <= t4).
!

ClassTestCase subclass: #TimeStampTest
	instanceVariableNames: 'timestamp aTimeStamp'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Chronology-Tests'!

!TimeStampTest commentStamp: 'brp 7/26/2003 22:44' prior: 0!
This is the unit test for the class TimeStamp.!

----- Method: TimeStampTest>>classToBeTested (in category 'Coverage') -----
classToBeTested

	^ self timestampClass!

----- Method: TimeStampTest>>selectorsToBeIgnored (in category 'Coverage') -----
selectorsToBeIgnored

	| deprecated private special |

	deprecated := #().
	private := #( #printOn: ).
	special := #().

	^ super selectorsToBeIgnored, deprecated, private, special.!

----- Method: TimeStampTest>>setUp (in category 'Running') -----
setUp

	timestamp := self timestampClass date: ('1-10-2000' asDate) time: ('11:55:00 am' asTime).

	aTimeStamp := TimeStamp readFrom: '1-02-2004 12:34:56 am' readStream!

----- Method: TimeStampTest>>tearDown (in category 'Running') -----
tearDown

	timestamp := nil.!

----- Method: TimeStampTest>>testAccessing (in category 'Tests') -----
testAccessing

	| d t |
	d := '1-10-2000' asDate.
	t := '11:55:00 am' asTime.

	self
		assert: (timestamp offset: Date defaultOffset) date = d;
		assert: (timestamp offset: Date defaultOffset) time = t.
!

----- Method: TimeStampTest>>testArithmetic (in category 'Tests') -----
testArithmetic

	| ts |
	ts := timestamp minusDays: 123.  	"9 September 1999, 11:55 am"
	ts := ts minusSeconds: 1056.			"9 September 1999, 11:37:24 am"
	ts := ts plusDays: 123.				"10 January 2000, 11:37:24 am"
	ts := ts plusSeconds: 1056.			"10 January 2000, 11:55 am"
	self
		assert: ts  = timestamp.

	!

----- Method: TimeStampTest>>testArithmeticAcrossDateBoundary (in category 'Tests') -----
testArithmeticAcrossDateBoundary

	| ts |
	ts := timestamp minusSeconds: ((11*3600) + (55*60) + 1).
	self
		assert: ts = ('1-9-2000 11:59:59 pm' asTimeStamp).

	!

----- Method: TimeStampTest>>testComparing (in category 'Tests') -----
testComparing

	| ts1 ts2 ts3 c1 c2 le |
	ts1 := self timestampClass date: ('01-10-2000' asDate) time: ('11:55:00 am' asTime).
	ts2 := self timestampClass date: ('07-26-2003' asDate) time: ('22:09:45 am' asTime).
	ts3 := self timestampClass date: ('05-28-1972' asDate) time: ('04:31:14 pm' asTime).

	self
		assert: ts1 = timestamp;
		assert: ts1 hash = timestamp hash;
		assert: timestamp = timestamp copy;
		assert: ts1 < ts2;
		deny: ts1 < ts3.

	c1 := self timestampClass current.
	c2 := self timestampClass current.
	le := (c1 <= c2).
	self assert: le.

!

----- Method: TimeStampTest>>testConverting (in category 'Tests') -----
testConverting

	| d t |
	d := '1-10-2000' asDate.
	t := '11:55:00 am' asTime.

	self
		assert: timestamp asSeconds = (d asSeconds + t asSeconds);
		assert: timestamp asDate = d;
		assert: timestamp asTime = t;
		assert: timestamp asTimeStamp == timestamp;
		assert: timestamp dateAndTime = {d. t}.
!

----- Method: TimeStampTest>>testDate (in category 'testing') -----
testDate
	self assert: aTimeStamp date = '01-02-2004' asDate!

----- Method: TimeStampTest>>testDateAndTime (in category 'testing') -----
testDateAndTime
	self assert: aTimeStamp dateAndTime
			= (Array with: '01-02-2004' asDate with: '00:34:56' asTime)!

----- Method: TimeStampTest>>testFromSeconds (in category 'Tests') -----
testFromSeconds
	"A time stamp from seconds is created in the local time zone, so offset may
	be non-zero. The test timestamp has offset zero (implying UTC). Comparison
	to the test timestamp should succeed if and only if both time stamps are
	created relative to the same time zone (UTC)."

	| local utc |
	local := self timestampClass fromSeconds: 3124958100.
	local offset = Duration zero
		ifTrue: [self assert: local = timestamp.]
		ifFalse: [self deny: local = timestamp.].
	utc := local offset: Duration zero.
	self assert: utc = timestamp.!

----- Method: TimeStampTest>>testFromString (in category 'Tests') -----
testFromString
	"This should signal an exception in 3.6beta as Time>>fromString: does not exist."

	self should: [ timestamp = (self timestampClass fromString: '1-10-2000 11:55:00 am') ] 

!

----- Method: TimeStampTest>>testInstanceCreation (in category 'Tests') -----
testInstanceCreation

	self 
		should: [ self timestampClass midnight asDuration = (0 hours) ];
		should: [ self timestampClass noon asDuration = (12 hours) ].
!

----- Method: TimeStampTest>>testMinusDays (in category 'testing') -----
testMinusDays
	self assert: (aTimeStamp minusDays: 5) dateAndTime
			= (Array with: '12-28-2003' asDate with: '00:34:56' asTime)!

----- Method: TimeStampTest>>testMinusSeconds (in category 'testing') -----
testMinusSeconds
	self assert: (aTimeStamp minusSeconds: 34 * 60 + 56) dateAndTime
			= (Array with: '01-02-2004' asDate with: '00:00:00' asTime)!

----- Method: TimeStampTest>>testMinusSecondsOverMidnight (in category 'testing') -----
testMinusSecondsOverMidnight
	self assert: (aTimeStamp minusSeconds: 34 * 60 + 57) dateAndTime
			= (Array with: '01-01-2004' asDate with: '23:59:59' asTime)
	"Bug The results are actual results are: #(1 January 2005 11:25:03 pm)"!

----- Method: TimeStampTest>>testPlusDays (in category 'testing') -----
testPlusDays
	self assert: (aTimeStamp plusDays: 366) dateAndTime
			= (Array with: '01-02-2005' asDate with: '00:34:56' asTime)!

----- Method: TimeStampTest>>testPlusSeconds (in category 'testing') -----
testPlusSeconds
	self assert: (aTimeStamp plusSeconds: 60 * 60 ) dateAndTime
			= (Array with: '01-02-2004' asDate with: '01:34:56' asTime)!

----- Method: TimeStampTest>>testPlusSecondsOverMidnight (in category 'testing') -----
testPlusSecondsOverMidnight
	self assert: (aTimeStamp plusSeconds: 24 * 60 * 60 + 1) dateAndTime
			= (Array with: '01-03-2004' asDate with: '00:34:57' asTime)!

----- Method: TimeStampTest>>testPrintOn (in category 'testing') -----
testPrintOn
	| ref ws |
	ref := '2 January 2004 12:34:56 am'.
	ws := '' writeStream.
	aTimeStamp printOn: ws.
	self assert: ws contents = ref!

----- Method: TimeStampTest>>testPrinting (in category 'Tests') -----
testPrinting

	self	
		assert: timestamp printString = '10 January 2000 11:55 am'.
!

----- Method: TimeStampTest>>testReadFromA1 (in category 'testing') -----
testReadFromA1
	"Conversion to and from a string (with implied UTC offset) is equal if
	and only if the time stamp has zero offset."
	|ts|
	ts := TimeStamp current offset: Duration zero. "current as UTC"
	self assert: (ts = (TimeStamp fromString: ts asString)).
	ts := TimeStamp current offset: (Duration hours: 1).
	self deny: (ts = (TimeStamp fromString: ts asString)).
!

----- Method: TimeStampTest>>testSorting (in category 'Tests') -----
testSorting

	| c1 c2 |
	c1 := self timestampClass current.
	c2 := self timestampClass current.

	self
		assert: (self timestampClass current) <= (self timestampClass current);
		assert: (c1 <= c2).


!

----- Method: TimeStampTest>>testStoreOn (in category 'testing') -----
testStoreOn
	| ref ws |
	ref := '''2 January 2004 12:34:56 am'' asTimeStamp'.
	ws := '' writeStream.
	aTimeStamp storeOn: ws.
	self assert: ws contents = ref!

----- Method: TimeStampTest>>testTime (in category 'testing') -----
testTime
	self assert: aTimeStamp time =  '00:34:56' asTime!

----- Method: TimeStampTest>>testTimeStamp (in category 'testing') -----
testTimeStamp
	self assert: aTimeStamp = aTimeStamp asTimeStamp
!

----- Method: TimeStampTest>>timestampClass (in category 'Private') -----
timestampClass

	^ TimeStamp!

ClassTestCase subclass: #TimeTest
	instanceVariableNames: 'time aTime localTimeZoneToRestore'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Chronology-Tests'!

!TimeTest commentStamp: '<historical>' prior: 0!
This is the unit test for the class Time.

!

----- Method: TimeTest>>classToBeTested (in category 'Coverage') -----
classToBeTested

	^ self timeClass!

----- Method: TimeTest>>selectorsToBeIgnored (in category 'Coverage') -----
selectorsToBeIgnored

	 | deprecated private special primitives timing benchmarks |

	deprecated := #().
	private := #( #print24:on: #print24:showSeconds:on: ).
	special := #( #< #= #new #printOn: #storeOn: ).
	primitives := #( #primMillisecondClock #primSecondsClock ).
	timing := #( #millisecondClockValue #milliseconds:since: #millisecondsSince: ).
	benchmarks := #( #benchmarkMillisecondClock #benchmarkPrimitiveResponseDelay ). 

	^ super selectorsToBeIgnored, deprecated, private, special, primitives, timing, benchmarks.!

----- Method: TimeTest>>setUp (in category 'Running') -----
setUp

	localTimeZoneToRestore := DateAndTime localTimeZone.
	DateAndTime localTimeZone: TimeZone default.
	time := self timeClass fromSeconds: 14567.		"4:02:47 am"
	aTime := Time readFrom: '12:34:56 pm' readStream
!

----- Method: TimeTest>>tearDown (in category 'Running') -----
tearDown
	DateAndTime localTimeZone: localTimeZoneToRestore.
!

----- Method: TimeTest>>testAccessing (in category 'Tests') -----
testAccessing

	self
		assert: time hours = 4;
		assert: time minutes = 2;
		assert: time seconds = 47;
		assert: time asSeconds = 14567.
!

----- Method: TimeTest>>testAddSeconds (in category 'testing') -----
testAddSeconds
	self assert: (aTime addSeconds: 1) = (Time readFromString: '12:34:57').
	self assert: (aTime addSeconds: 60) = (Time readFromString: '12:35:56').	
	self assert: (aTime addSeconds: 3600) = (Time readFromString: '13:34:56').
	self assert: (aTime addSeconds: 24*60*60) = (Time readFromString: '12:34:56').!

----- Method: TimeTest>>testAddTime (in category 'testing') -----
testAddTime
	self assert: (aTime addTime: aTime) = (Time readFromString: '01:09:52').
!

----- Method: TimeTest>>testArithmetic (in category 'Tests') -----
testArithmetic
	| t1 t2 t3 |
	t1 := time addSeconds: 70.		"4:03:57 am"
	self
		assert: t1 hours = 4;
		assert: t1 minutes = 3;
		assert: t1 seconds = 57.

	t2 := t1 addTime: (self timeClass fromSeconds: (60*60*5)).
	self
		assert: t2 hours = 9;
		assert: t2 minutes = 3;
		assert: t2 seconds = 57.

	t3 := t2 subtractTime: (self timeClass fromSeconds: (60*60*5) + 70).
	self
		assert: t3 = time.
!

----- Method: TimeTest>>testAsDate (in category 'testing') -----
testAsDate
	self assert: (aTime asDate) = (Date current)
!

----- Method: TimeTest>>testAsDateAndTime (in category 'testing') -----
testAsDateAndTime
	self assert: (aTime asDateAndTime) = (DateAndTime current midnight + aTime)
!

----- Method: TimeTest>>testAsDuration (in category 'testing') -----
testAsDuration
	self assert: (aTime asDuration) = (Duration days: 0 hours: 12 minutes: 34 seconds: 56)
!

----- Method: TimeTest>>testAsNanoSeconds (in category 'testing') -----
testAsNanoSeconds
	self assert: (aTime asNanoSeconds) = 45296000000000

!

----- Method: TimeTest>>testAsSeconds (in category 'testing') -----
testAsSeconds
	self assert: (aTime asSeconds) = 45296
!

----- Method: TimeTest>>testAsTime (in category 'testing') -----
testAsTime
	self assert: (aTime asTime) = aTime

!

----- Method: TimeTest>>testAsTimeStamp (in category 'testing') -----
testAsTimeStamp
	self assert: (aTime asTimeStamp) = (DateAndTime current midnight + aTime) asTimeStamp
!

----- Method: TimeTest>>testAsWeek (in category 'testing') -----
testAsWeek
	self assert: aTime asWeek = (DateAndTime current midnight + aTime) asWeek
!

----- Method: TimeTest>>testAsYear (in category 'testing') -----
testAsYear
	self assert: aTime asYear = (DateAndTime current midnight + aTime) asYear
!

----- Method: TimeTest>>testComparing (in category 'Tests') -----
testComparing
	| t1 t2 t3 |
	t1 := self timeClass fromSeconds: 14567.		"4:02:47 am"
	t2 := self timeClass fromSeconds: 5000.		"1:23:20 am"
	t3 := self timeClass fromSeconds: 80000.		"10:13:20 pm"

	self
		assert: time = t1;
		assert: time hash = t1 hash;
		assert: time = time copy.
	self
		deny: t1 < t2;
		assert: t1 < t3.!

----- Method: TimeTest>>testConverting (in category 'Tests') -----
testConverting

	self
		assert: time asSeconds = 14567.!

----- Method: TimeTest>>testDuration (in category 'testing') -----
testDuration
	self assert: aTime duration = 0 seconds!

----- Method: TimeTest>>testEqual (in category 'testing') -----
testEqual
	self assert: aTime = (Time readFromString: '12:34:56').!

----- Method: TimeTest>>testFromSeconds (in category 'Tests') -----
testFromSeconds
	| t |
	t := self timeClass fromSeconds: 14567.
	self
		assert: t = time
!

----- Method: TimeTest>>testGeneralInquiries (in category 'Tests') -----
testGeneralInquiries
	| now d t dt epsilon |

	"vm clocks seem to work differently across platforms, so an epsilon is required"
	epsilon := 1. "second"
	now  := self timeClass dateAndTimeNow.
	self 
		assert: now size = 2;
		assert: (now last asSeconds - self timeClass now asSeconds) abs <= epsilon.

	self should: [ self timeClass timeWords ] raise: MessageNotUnderstood.

	d := '2 June 1973' asDate.
	t := '4:02:47 am' asTime.
	dt := self timeClass dateAndTimeFromSeconds: (2285280000 + 14567).
	self
		assert: dt = {d. t.}.
!

----- Method: TimeTest>>testHash (in category 'testing') -----
testHash
	self assert: aTime hash = (Character instSize > 0 ifTrue: [607004] ifFalse: [101409191])!

----- Method: TimeTest>>testHhmm24 (in category 'testing') -----
testHhmm24
	self assert: aTime hhmm24 = '1234'!

----- Method: TimeTest>>testHour (in category 'testing') -----
testHour
	self assert: aTime hour =  12.
	self assert: aTime hour12 =  12.
	self assert: aTime hour24 =  12.
	self assert: aTime hours =  12.!

----- Method: TimeTest>>testHumanWordsForSecondsAgo (in category 'testing') -----
testHumanWordsForSecondsAgo
	self assert: (Time humanWordsForSecondsAgo: 0.999999999)
			= 'a second ago'.
	self assert: (Time humanWordsForSecondsAgo: 44.99999999)
			= '44.99999999 seconds ago'.
	self assert: (Time humanWordsForSecondsAgo: 89.999999999)
			= 'a minute ago'.
	self assert: (Time humanWordsForSecondsAgo: 2699.999999999)
			= '44 minutes ago'.
	self assert: (Time humanWordsForSecondsAgo: 5399.999999999)
			= 'an hour ago'.
	self assert: (Time humanWordsForSecondsAgo: 64799.999999999)
			= '17 hours ago'.
	!

----- Method: TimeTest>>testHumanWordsForSecondsAgoWithDays (in category 'testing') -----
testHumanWordsForSecondsAgoWithDays

	self assert: (Time humanWordsForSecondsAgo: 18 * 60 * 60)
					= 'yesterday'.
	self assert: (Time humanWordsForSecondsAgo: 24 * 60 * 60)
					= 'yesterday'.
!

----- Method: TimeTest>>testLessThan (in category 'testing') -----
testLessThan
	self assert: aTime < (Time readFromString: '12:34:57').!

----- Method: TimeTest>>testMeridianAbbreviation (in category 'testing') -----
testMeridianAbbreviation
	self assert: aTime meridianAbbreviation =  'PM'.
!

----- Method: TimeTest>>testMinute (in category 'testing') -----
testMinute
	self assert: aTime minute =  34.
	self assert: aTime minutes =  34
!

----- Method: TimeTest>>testNanoSecond (in category 'testing') -----
testNanoSecond
	self assert: aTime nanoSecond = 0
	"Right now all times all seconds"
!

----- Method: TimeTest>>testNew (in category 'Tests') -----
testNew
	
	self assert: self timeClass new asSeconds = 0!

----- Method: TimeTest>>testPrint24 (in category 'testing') -----
testPrint24
	self assert: aTime print24 = '12:34:56'!

----- Method: TimeTest>>testPrint24On (in category 'testing') -----
testPrint24On
	| referenceString printed |
	referenceString := '12:34:56'.
	printed := WriteStream on: ''.
	aTime print24: true on: printed.
	self assert: printed contents = referenceString!

----- Method: TimeTest>>testPrint24OnWithPM (in category 'testing') -----
testPrint24OnWithPM
	| referenceString printed |
	referenceString := '12:34:56 pm'.
	printed := WriteStream on: ''.
	aTime print24: false on: printed.
	^ self assert: printed contents = referenceString!

----- Method: TimeTest>>testPrint24OnWithoutSeconds (in category 'testing') -----
testPrint24OnWithoutSeconds
	| referenceString printed |
	referenceString := '12:34'.
	printed := WriteStream on: ''.
	aTime print24: true showSeconds: false on: printed.
	self assert: printed contents = referenceString!

----- Method: TimeTest>>testPrintMinutes (in category 'testing') -----
testPrintMinutes
	self assert: aTime printMinutes = '12:34 pm'!

----- Method: TimeTest>>testPrintOn (in category 'testing') -----
testPrintOn
	| referenceString printed |
	referenceString := '12:34:56 pm'.
	printed := WriteStream on: ''.
	aTime printOn: printed.
	self assert: printed contents = referenceString!

----- Method: TimeTest>>testPrinting (in category 'Tests') -----
testPrinting

	self	
		assert: time printString = '4:02:47 am';
		assert: time intervalString =  '4 hours 2 minutes 47 seconds';
		assert: time print24 = '04:02:47';
		assert: time printMinutes = '4:02 am';
		assert: time hhmm24 = '0402'.
!

----- Method: TimeTest>>testReadFrom (in category 'Tests') -----
testReadFrom

	| t1 t2 |
	t1 := self timeClass readFrom: '4:02:47 am' readStream.
	t2 := self timeClass readFrom: '4:02:47.000 am' readStream.

	self
		assert: time = t1;
		assert: time = t2
!

----- Method: TimeTest>>testSecond (in category 'testing') -----
testSecond
	self assert: aTime second =  56.
	self assert: aTime seconds =  56
!

----- Method: TimeTest>>testSqueakInquiries (in category 'Tests') -----
testSqueakInquiries
	| timewords totalseconds condensed corrected |
	self assert: 
		(self timeClass namesForTimes: #(2 10000023 10000026))
			= #('January, 1901' 'April, 1901, 4/26/1901, 5:47 pm' 'April, 1901, 4/26/1901, 5:47 pm').

	timewords := #(0.5 30 62 130 4000 10000 60000 86401) 
		collect: [ :ss | self timeClass humanWordsForSecondsAgo: ss ].
	self assert: 
		timewords = #('a second ago' '30 seconds ago' 'a minute ago' '2 minutes ago' 
			'an hour ago' '2 hours ago' '16 hours ago' 'yesterday').

	totalseconds :=  self timeClass totalSeconds.
	condensed := self timeClass condenseBunches: 
		(#(20 400 401  20000 20200 20300 40000 45000  200000 201000 202000) 
			collect: [:tt | totalseconds - tt]).
	corrected := condensed collect: [ :e | totalseconds - e ].
	self
		assert: (corrected includesAllOf: #(20 400 401 20000 40000 45000 200000)).
!

----- Method: TimeTest>>testStoreOn (in category 'testing') -----
testStoreOn
	| referenceString stored |
	referenceString := '''12:34:56 pm'' asTime'.
	stored := WriteStream on: ''.
	aTime storeOn: stored.
	self assert: stored contents = referenceString!

----- Method: TimeTest>>testStoring (in category 'Tests') -----
testStoring

	self	
		assert: time storeString = '''4:02:47 am'' asTime';
		assert: time = ('4:02:47 am' asTime).
!

----- Method: TimeTest>>testSubtractTime (in category 'testing') -----
testSubtractTime
	self assert: (aTime subtractTime: aTime) = (Time readFrom: (ReadStream on: '00:00:00'))
!

----- Method: TimeTest>>testTicks (in category 'testing') -----
testTicks
	self assert: aTime ticks = #(0 45296 0).
	self assert: aTime  = (Time new ticks: #(0 45296 0))!

----- Method: TimeTest>>testTimeStamp (in category 'testing') -----
testTimeStamp
	self assert: aTime = aTime asTimeStamp asTime!

----- Method: TimeTest>>timeClass (in category 'Private') -----
timeClass

	^ Time!

ClassTestCase subclass: #TimespanTest
	instanceVariableNames: 'timespan aTimespan anOverlappingTimespan anIncludedTimespan aDisjointTimespan aDay aWeek dec31 jan01 jan08 localTimeZoneToRestore anEqualTimeSpan'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Chronology-Tests'!

----- Method: TimespanTest>>classToBeTested (in category 'Coverage') -----
classToBeTested

	^ Timespan
!

----- Method: TimespanTest>>setUp (in category 'Running') -----
setUp

	| jan01HereSomeWhereElseOnEarth |
	localTimeZoneToRestore := DateAndTime localTimeZone.
	DateAndTime localTimeZone: TimeZone default.

	"100 hours starting noon 22 March 2003"
	timespan := Timespan starting:
					(DateAndTime year: 2003 month: 03 day: 22 hour: 12 minute: 0 second: 0)
						duration: (Duration hours: 100).

	dec31 := (DateAndTime year: 2004 month: 12 day: 31 hour: 0 minute: 0 second: 0).
	jan01 := (DateAndTime year: 2005 month: 1 day: 1 hour: 0 minute: 0 second: 0).
	jan08 := (DateAndTime year: 2005 month: 1 day: 8 hour: 0 minute: 0 second:0).
	aDay := Duration days: 1 hours: 0 minutes: 0 seconds: 0 nanoSeconds: 0.
	aWeek := Duration days: 7 hours: 0 minutes: 0 seconds: 0 nanoSeconds: 0.
	aTimespan := Timespan starting: jan01 duration: aWeek.
	jan01HereSomeWhereElseOnEarth := DateAndTime new ticks: (jan01 + 3 hours) ticks offset: jan01 offset + 3 hours.
	anEqualTimeSpan := Timespan starting: jan01HereSomeWhereElseOnEarth asUTC duration: aWeek.
	anOverlappingTimespan := Timespan starting: dec31 duration: aWeek.
	anIncludedTimespan := Timespan starting: jan01 duration: aDay.
	aDisjointTimespan := Timespan starting: jan08 duration: aWeek.



!

----- Method: TimespanTest>>tearDown (in category 'Running') -----
tearDown
	DateAndTime localTimeZone: localTimeZoneToRestore.
	timespan := nil
!

----- Method: TimespanTest>>testAccessing (in category 'Tests') -----
testAccessing

	self 
		assert: (timespan start =
				 (DateAndTime year: 2003 month: 03 day: 22 hour: 12 minute: 0 second: 0));
		assert: timespan duration = (Duration hours: 100);
		assert: timespan month = 3;
		assert: timespan monthName = 'March';
		assert: timespan monthAbbreviation = 'Mar'
		

!

----- Method: TimespanTest>>testArithmetic (in category 'Tests') -----
testArithmetic

	| ts1 ts2 d |
	ts1 := timespan + 2 days.
	ts2 := ts1 - 2 days.
	d := ts1 - (DateAndTime year: 2003 month: 03 day: 20).

	self 
		assert: (ts1 start = 
				 (DateAndTime year: 2003 month: 03 day: 24 hour: 12 minute: 0 second: 0));
		assert: (ts1 duration = timespan duration);
		assert: (ts2 start = timespan start);
		assert: (ts2 duration = timespan duration).

	self
		assert: d = (Duration days: 4 hours: 12 minutes: 0 seconds: 0)

!

----- Method: TimespanTest>>testAsDate (in category 'testing') -----
testAsDate
	self assert: aTimespan asDate =   jan01 asDate.
	"MessageNotUnderstood: Date class>>starting:"
!

----- Method: TimespanTest>>testAsDateAndTime (in category 'testing') -----
testAsDateAndTime
	self assert: aTimespan asDateAndTime =   jan01.
	"MessageNotUnderstood: Date class>>starting:"
	
!

----- Method: TimespanTest>>testAsDuration (in category 'testing') -----
testAsDuration
	self assert: aTimespan asDuration =  aWeek.

	
	
!

----- Method: TimespanTest>>testAsMonth (in category 'testing') -----
testAsMonth
	self assert: aTimespan asMonth =   jan01 asMonth.
!

----- Method: TimespanTest>>testAsTime (in category 'testing') -----
testAsTime
	self assert: aTimespan asTime =  jan01 asTime
	"MessageNotUnderstood: Time class>>seconds:nanoSeconds:"
 !

----- Method: TimespanTest>>testAsTimeStamp (in category 'testing') -----
testAsTimeStamp
	self assert: aTimespan asTimeStamp =  ((TimeStamp readFrom: '1-01-2005 0:00 am' readStream) offset: 0 hours).
!

----- Method: TimespanTest>>testAsWeek (in category 'testing') -----
testAsWeek
	self assert: aTimespan asWeek =   jan01 asWeek.
	"DateAndTime new asWeek
	 MessageNotUnderstood: Week class>>starting:"
!

----- Method: TimespanTest>>testAsYear (in category 'testing') -----
testAsYear
	self assert: aTimespan asYear =   jan01 asYear.

!

----- Method: TimespanTest>>testClockPrecisionDuration (in category 'testing') -----
testClockPrecisionDuration
	| ts |
	ts := Timespan starting: Date today duration: DateAndTime clockPrecision.
	self
		assert: ts start = ts end!

----- Method: TimespanTest>>testCurrent (in category 'testing') -----
testCurrent
	self assert: (Timespan starting: DateAndTime current)
			<= Timespan current.
	self assert:  Timespan current
			<= (Timespan starting: DateAndTime current)!

----- Method: TimespanTest>>testDateToday (in category 'testing') -----
testDateToday
	self assert: Date today start offset isZero!

----- Method: TimespanTest>>testDay (in category 'testing') -----
testDay
	self assert: aTimespan day =   jan01 day
!

----- Method: TimespanTest>>testDayOfMonth (in category 'testing') -----
testDayOfMonth
	self assert: aTimespan dayOfMonth  = 1.
!

----- Method: TimespanTest>>testDayOfWeek (in category 'testing') -----
testDayOfWeek
	self assert: aTimespan  dayOfWeek  = 7.
	self assert: aTimespan  dayOfWeekName = 'Saturday'.
!

----- Method: TimespanTest>>testDayOfYear (in category 'testing') -----
testDayOfYear
	self assert: aTimespan  dayOfYear  = 1.
	"MessageNotUnderstood: UndefinedObject>>year:, Undefined object is Year class"
!

----- Method: TimespanTest>>testDaysInMonth (in category 'testing') -----
testDaysInMonth
	self assert: aTimespan  daysInMonth  = 31.
	"MessageNotUnderstood: Month class>>starting:"
!

----- Method: TimespanTest>>testDaysInYear (in category 'testing') -----
testDaysInYear
	self assert: aTimespan  daysInYear  = 365.
	"MessageNotUnderstood: UndefinedObject>>starting:  UndefinedObject is Year class"
!

----- Method: TimespanTest>>testDaysLeftInYear (in category 'testing') -----
testDaysLeftInYear
	self assert: aTimespan  daysLeftInYear  = 364.
	"MessageNotUnderstood: UndefinedObject>>starting:  UndefinedObject is Year class"
!

----- Method: TimespanTest>>testDoWith (in category 'testing') -----
testDoWith
	| count |
	count := 0.
	aTimespan
		do: [:each | count := count + 1]
		with: (Timespan starting: jan01 duration: aDay).
	self assert: count = 7!

----- Method: TimespanTest>>testDoWithWhen (in category 'testing') -----
testDoWithWhen
	| count |
	count := 0.
	aTimespan
		do: [:each | count := count + 1]
		with: (Timespan starting: jan01 duration: aDay)
		when: [:each | count < 5].
	self assert: count = 5!

----- Method: TimespanTest>>testDuration (in category 'testing') -----
testDuration
	self assert: aTimespan duration  = aWeek.
	aTimespan duration: aDay.
	self assert: aTimespan duration =  aDay.

!

----- Method: TimespanTest>>testEnd (in category 'testing') -----
testEnd
	self assert: aTimespan end + (Duration  nanoSeconds:1)  =  aDisjointTimespan start.
	self assert: aTimespan end = (DateAndTime year: 2005 month: 1 day: 7 hour: 23 minute: 59 second: 59 nanoSecond: 999999999 offset: 0 hours)
!

----- Method: TimespanTest>>testEveryDo (in category 'testing') -----
testEveryDo
	| count duration |
	count := 0.
	duration := 7 days.
	aTimespan
		every: duration
		do: [:each | count := count + 1].
	self assert: count = 1!

----- Method: TimespanTest>>testFirstDayOfMonth (in category 'testing') -----
testFirstDayOfMonth
	self assert: aTimespan firstDayOfMonth =   1. 
	self assert: aDisjointTimespan firstDayOfMonth =   1
!

----- Method: TimespanTest>>testHash (in category 'testing') -----
testHash
	self assert: (aTimespan = anEqualTimeSpan) ==> [aTimespan hash = anEqualTimeSpan hash]!

----- Method: TimespanTest>>testIncludes (in category 'testing') -----
testIncludes
	self assert: (aTimespan includes: jan01).
	self deny: (aTimespan includes: jan08)
!

----- Method: TimespanTest>>testIncludesAllOf (in category 'testing') -----
testIncludesAllOf
	self assert: (aTimespan includesAllOf: (Bag with: jan01)).
	self deny: (aTimespan includesAllOf: (Bag with: jan01 with: jan08))
!

----- Method: TimespanTest>>testIncludesAnyOf (in category 'testing') -----
testIncludesAnyOf
	self deny: (aTimespan includesAnyOf: (Bag with: dec31)).
	self assert: (aTimespan includesAnyOf: (Bag with: jan01 with: jan08))
	"Error is due to bug in Timespan 
includesAnyOf: aCollection "
	"Answer whether any element of aCollection is included in the receiver"
	"aCollection do: [ :elem | (self includes: elem) ifTrue: [^ true]].
Shouldn't this return false if none are included?
"
!

----- Method: TimespanTest>>testInclusion (in category 'Tests') -----
testInclusion

	| t1 t2 t3 t4 |
	t1 := timespan start.
	t2 := timespan start + (timespan duration / 2).
	t3 := timespan end.
	t4 := timespan start + (timespan duration).

	self 
		assert: (timespan includes: t1);
		assert: (timespan includes: t2);
		assert: (timespan includes: t3)";
		deny: (timespan includes: t4).
	self
		assert: (timespan includes: (t1 to: t2));
		assert: (timespan includes: (t1 to: t4));
		deny: (timespan includes: (Timespan starting: t2 duration: (timespan duration * 2))).
	self 
		assert: (timespan includesAllOf: { t1. t2. t3 } );
		deny: (timespan includesAllOf: { t1. t2. t3. t4} ).
	self 
		assert: (timespan includesAnyOf: { t1. t2. t3 } );
		deny: (timespan includesAnyOf: { t4 } ).
"!

----- Method: TimespanTest>>testIntersectionWithDisjoint (in category 'testing') -----
testIntersectionWithDisjoint
	self assert: (aTimespan intersection: aDisjointTimespan) isNil.
!

----- Method: TimespanTest>>testIntersectionWithIncluded (in category 'testing') -----
testIntersectionWithIncluded
	self assert: (aTimespan intersection: anIncludedTimespan)  = 
	(Timespan starting: jan01 duration: (Duration days: 0 hours: 23 minutes: 59 seconds: 59 nanoSeconds: 999999999)).		
	self deny: (aTimespan intersection: anIncludedTimespan)	= anIncludedTimespan
!

----- Method: TimespanTest>>testIntersectionWithOverlapping (in category 'testing') -----
testIntersectionWithOverlapping
	self assert: (aTimespan intersection: anOverlappingTimespan)  = 
	(Timespan starting: jan01 duration: (Duration days: 5 hours: 23 minutes: 59 seconds: 59 nanoSeconds: 999999999)).		

!

----- Method: TimespanTest>>testIntersectionWithSelf (in category 'testing') -----
testIntersectionWithSelf
	self assert: (aTimespan intersection: aTimespan)  = 
	(Timespan starting: jan01 duration: (Duration days: 6 hours: 23 minutes: 59 seconds: 59 nanoSeconds: 999999999)).		
	self deny: (aTimespan intersection: anIncludedTimespan)	= aTimespan
!

----- Method: TimespanTest>>testIntersectionWithSeparate (in category 'testing') -----
testIntersectionWithSeparate
	self assert: (aTimespan intersection: aDisjointTimespan) isNil.
	self deny: (aTimespan intersection: anOverlappingTimespan) isNil.
	self assert: (aTimespan intersection: anIncludedTimespan)  = 
	(Timespan starting: jan01 duration: (Duration days: 0 hours: 23 minutes: 59 seconds: 59 nanoSeconds: 999999999)).		
	self deny: (aTimespan intersection: anIncludedTimespan)	= anIncludedTimespan
!

----- Method: TimespanTest>>testIsLeapYear (in category 'testing') -----
testIsLeapYear
	"self assert: anOverlappingTimespan isLeapYear."
	"not sure why this fails"
	self deny: aTimespan isLeapYear
!

----- Method: TimespanTest>>testJulianDayNumber (in category 'testing') -----
testJulianDayNumber
	self assert: aTimespan julianDayNumber =  (jan01 julianDayNumber).
!

----- Method: TimespanTest>>testLessThan (in category 'testing') -----
testLessThan
	self assert: aTimespan  < aDisjointTimespan.
	self deny: anIncludedTimespan < aTimespan
	!

----- Method: TimespanTest>>testMinusADateAndTime (in category 'testing') -----
testMinusADateAndTime
	"It appears that subtracting a date from a Timespan gives you a duration = to the difference between the start of the timespan and the date "
	self assert: aTimespan - dec31 =  aDay.
	self assert: aDisjointTimespan - jan01 =  aWeek.


!

----- Method: TimespanTest>>testMinusADuration (in category 'testing') -----
testMinusADuration
	"It appears that subtracting a duration from a Timespan gives you a Timespan shifted by the duration"
	self assert: aTimespan - aDay =  anOverlappingTimespan.
	self assert: aDisjointTimespan - aWeek =  aTimespan.	


!

----- Method: TimespanTest>>testMonth (in category 'testing') -----
testMonth
	self assert: aTimespan month  = 1.
	self assert: aTimespan monthName = 'January'.
	self assert: aTimespan monthIndex = 1.!

----- Method: TimespanTest>>testNew (in category 'testing') -----
testNew
	self assert: Timespan new = (Timespan starting: '01-01-1901' asDate)!

----- Method: TimespanTest>>testNext (in category 'testing') -----
testNext
	self assert: aTimespan next = aDisjointTimespan
!

----- Method: TimespanTest>>testPlus (in category 'testing') -----
testPlus
	self assert: aTimespan + aWeek = aDisjointTimespan.
	self assert: anOverlappingTimespan + aDay = aTimespan.
!

----- Method: TimespanTest>>testPrevious (in category 'testing') -----
testPrevious
	self assert: aTimespan  = aDisjointTimespan previous.
	self assert: aTimespan next previous = aTimespan 
!

----- Method: TimespanTest>>testPrintOn (in category 'testing') -----
testPrintOn
	| ref ws |
	ref := 'a Timespan(2005-01-01T00:00:00+00:00D7:00:00:00)'.
	ws := '' writeStream.
	aTimespan printOn: ws.
	self assert: ws contents = ref
!

----- Method: TimespanTest>>testRematerializedDateComparison (in category 'testing') -----
testRematerializedDateComparison
	"Tests whether comparison semantics are affected by serialization / rematerialization."
	| isItTrue date refStream rwstream | date := Date today.
	isItTrue := DateAndTime now asDate = date.
	self assert: (date = DateAndTime now asDate) = isItTrue.
	self assert: (DateAndTime now asDate = date) = isItTrue.
	rwstream := RWBinaryOrTextStream on: ByteArray new.
	refStream := ReferenceStream on: rwstream..
	refStream nextPut: date; close.
	rwstream position: 0.
	refStream := ReferenceStream on: rwstream.
	date := refStream next.
	refStream close.
	self assert: (date = DateAndTime now asDate) = isItTrue.
	self assert: (DateAndTime now asDate = date) = isItTrue.
!

----- Method: TimespanTest>>testStart (in category 'testing') -----
testStart
	self assert: aTimespan start =   jan01.
	aTimespan start: jan08.
	self assert: aTimespan start =   jan08.!

----- Method: TimespanTest>>testStartingEnding (in category 'testing') -----
testStartingEnding
	self assert: aTimespan  = (Timespan starting: jan01 ending: jan08)
!

----- Method: TimespanTest>>testTo (in category 'testing') -----
testTo
	self assert: (anIncludedTimespan to: jan08) = aTimespan 
!

----- Method: TimespanTest>>testUnion (in category 'Tests') -----
testUnion

	| union |
	union := timespan union: timespan.
	
	self 
		assert: (union start = timespan start);
		assert: (union duration = timespan duration)
!

----- Method: TimespanTest>>testUnionWithDisjoint (in category 'testing') -----
testUnionWithDisjoint

	self assert: (aTimespan union: aDisjointTimespan)  = 
		(Timespan starting: jan01 duration: (14 days)).	
			
!

----- Method: TimespanTest>>testUnionWithIncluded (in category 'testing') -----
testUnionWithIncluded

	self 
		assert: (aTimespan union: anIncludedTimespan) = aTimespan 	!

----- Method: TimespanTest>>testUnionWithOverlapping (in category 'testing') -----
testUnionWithOverlapping

	self 
		assert: (aTimespan union: anOverlappingTimespan)  = 
				(Timespan starting: dec31 duration: (8 days))!

----- Method: TimespanTest>>testUnionWithSelf (in category 'testing') -----
testUnionWithSelf
	self assert: (aTimespan union: aTimespan) = aTimespan
	!

----- Method: TimespanTest>>testUnionWithSeparate (in category 'testing') -----
testUnionWithSeparate

	self 
		assert: (anOverlappingTimespan union: aDisjointTimespan) = 
			(Timespan 
				starting: anOverlappingTimespan start
				ending:  (aDisjointTimespan end + DateAndTime clockPrecision))
			
!

----- Method: TimespanTest>>testWorkDatesDo (in category 'testing') -----
testWorkDatesDo
	| count |
	count := 0.
	aTimespan
		workDatesDo: [:each | count := count + 1].
	self assert: count = 5!

----- Method: TimespanTest>>testYear (in category 'testing') -----
testYear
	self assert: aTimespan year = 2005.

	!

----- Method: TimespanTest>>testZeroDuration (in category 'testing') -----
testZeroDuration
	| ts |
	ts := Timespan starting: Date today duration: Duration zero.
	self
		assert: ts start = ts end!

ClassTestCase subclass: #WeekTest
	instanceVariableNames: 'week restoredStartDay'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Chronology-Tests'!

----- Method: WeekTest>>classToBeTested (in category 'Coverage') -----
classToBeTested

	^ Week!

----- Method: WeekTest>>selectorsToBeIgnored (in category 'Coverage') -----
selectorsToBeIgnored

	| deprecated private special |

	deprecated := #().
	private := #( #printOn: ).
	special := #( #next #do: ).

	^ super selectorsToBeIgnored, deprecated, private, special.!

----- Method: WeekTest>>setUp (in category 'Running') -----
setUp
	"June 1998, 5th week"

	super setUp.
	restoredStartDay := Week startDay.
	Week startDay: #Sunday.
	week := Week starting: '4 July 1998' asDate!

----- Method: WeekTest>>tearDown (in category 'Running') -----
tearDown

	super tearDown.
	Week startDay: restoredStartDay.
	week := nil.

!

----- Method: WeekTest>>testDayNames (in category 'Tests') -----
testDayNames
	self assert: (Week dayNames) = #(#Sunday #Monday #Tuesday #Wednesday #Thursday #Friday #Saturday).!

----- Method: WeekTest>>testEnumerating (in category 'Tests') -----
testEnumerating

	| days |
	days := OrderedCollection new.
	0 to: 6 do: [ :i | days add: ('28 June 1998' asDate addDays: i) ].

	week datesDo: [ :d | days remove: d ].
	
	self assert: days isEmpty.
!

----- Method: WeekTest>>testIndexOfDay (in category 'Tests') -----
testIndexOfDay
	| days |
	days := #(#Sunday #Monday #Tuesday #Wednesday #Thursday #Friday #Saturday).
	
	days withIndexDo: [:item :index | self assert: (Week indexOfDay: item) = index].
	
	"This should probably raise an error rather than returning 0."
	self assert: (Week indexOfDay: 0) = 0.
	self assert: (Week indexOfDay: 1) = 0.
	self assert: (Week indexOfDay: 7) = 0.
	self assert: (Week indexOfDay: 8) = 0.
	self assert: (Week indexOfDay: #Sunnyday) = 0.!

----- Method: WeekTest>>testInquiries (in category 'Tests') -----
testInquiries

	self
		assert: week start asDate = '28 June 1998' asDate;
		assert: week end asDate = '4 July 1998' asDate;
		assert: week index = 5;
		assert: week duration = (7 days).
!

----- Method: WeekTest>>testNameOfDay (in category 'Tests') -----
testNameOfDay
	| days |
	days := #(#Sunday #Monday #Tuesday #Wednesday #Thursday #Friday #Saturday).
	
	days withIndexDo: [:item :index | self assert: (Week nameOfDay: index) = item].
	
	self should: [Week nameOfDay: 0] raise: TestResult error.
	self should: [Week nameOfDay: 8] raise: TestResult error.
	self should: [Week nameOfDay: #Sunday] raise: TestResult error.!

----- Method: WeekTest>>testPreviousNext (in category 'Tests') -----
testPreviousNext
	self
		assert: week next = (Week starting: '6 July 1998' asDate);
		assert: week previous = (Week starting:  '22 June 1998' asDate)!

ClassTestCase subclass: #YearTest
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Chronology-Tests'!

----- Method: YearTest>>classToBeTested (in category 'Coverage') -----
classToBeTested

	^ Year!

----- Method: YearTest>>testCurrent (in category 'Tests') -----
testCurrent
	self assert:
		Year current start =
			((DateAndTime
				year: DateAndTime now year
				month: 1
				day: 1) offset: Year defaultOffset)!

----- Method: YearTest>>testPreviousInLeapYear (in category 'Tests') -----
testPreviousInLeapYear

	| leap |
	leap := Year year: 2008.
	self assert: leap isLeapYear. 
	self assert: (Year year: (leap year - 1)) = leap previous !



More information about the Packages mailing list