"{ Package: 'exept:regression' }"
"{ NameSpace: RegressionTests }"
TestCase subclass:#TimeAndDateTest
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'tests-Regression-DateAndTime'
!
!TimeAndDateTest methodsFor:'Testing'!
test_01_ReadingTimes
self assert:(Time readFrom:'0:00' ) = (Time hour:0 minute:0 second:0).
self assert:(Time readFrom:'2:00' ) = (Time hour:2 minute:0 second:0).
self assert:(Time readFrom:'12:00' ) = (Time hour:12 minute:0 second:0).
self assert:(Time readFrom:'14:00' ) = (Time hour:14 minute:0 second:0).
self assert:(Time readFrom:'23:00' ) = (Time hour:23 minute:0 second:0).
self assert:(Time readFrom:'24:00' ) = (Time hour:0 minute:0 second:0).
self assert:(Time readFrom:'2:30 am' ) = (Time hour:2 minute:30 second:0).
self assert:(Time readFrom:'2:30 pm' ) = (Time hour:14 minute:30 second:0).
self assert:(Time readFrom:'14' ) = (Time hour:14 minute:0 second:0).
self assert:(Time readFrom:'2 am' ) = (Time hour:2 minute:0 second:0).
self assert:(Time readFrom:'2 pm' ) = (Time hour:14 minute:0 second:0).
self assert:(Time readFrom:'12:05 pm') = (Time hour:12 minute:5 second:0).
self assert:(Time readFrom:'12:06 am') = (Time hour:0 minute:6 second:0).
self assert:(Time readFrom:'18:22:00') = (Time hour:18 minute:22 second:0).
self assert:(Time readFrom:'14:00:11') = (Time hour:14 minute:0 second:11).
self assert:(Time readFrom:'7:00:11' ) = (Time hour:7 minute:0 second:11).
self assert:(Time readFrom:'24:00:00') = (Time hour:0 minute:0 second:0).
self assert:(Time readFrom:'0:00:00' ) = (Time hour:0 minute:0 second:0).
self assert:(Time readFrom:'12:00:00') = (Time hour:12 minute:0 second:0).
self assert:(Time readFrom:'0:00:00' ) = (Time hour:0 minute:0 second:0).
self assert:(Time readFrom:'6:22:00 pm' ) = (Time hour:18 minute:22 second:0).
self assert:(Time readFrom:'2:00:11 pm' ) = (Time hour:14 minute:0 second:11).
self assert:(Time readFrom:'7:00:11 am' ) = (Time hour:7 minute:0 second:11).
self assert:(Time readFrom:'12:00:00 am') = (Time hour:0 minute:0 second:0).
self assert:(Time readFrom:'0:00:00 am' ) = (Time hour:0 minute:0 second:0).
self should:[ Time readFrom:'24:00:00 am' ] raise:TimeConversionError.
self assert:(Time readFrom:'12:00:00 pm') = (Time hour:12 minute:0 second:0).
self assert:(Time readFrom:'0:00:00 pm' onError:'invalid') = 'invalid'.
self should:[ Time readFrom:'24:00:00 pm' ] raise:TimeConversionError.
"
self new test_01_Reading
"
!
test_02_ReadingDates
self assert:(Date
readFrom:'2-may-2010'
printFormat:'%d-%shortMonthName-%y'
language:'en'
onError:[self error]
) = (Date newDay:2 month:5 year:2010).
{
{ '3-jan-2012' . (Date newDay:3 month:1 year:2012) } .
{ '15-feb-2012' . (Date newDay:15 month:2 year:2012) } .
{ '06-mar-2011' . (Date newDay:6 month:3 year:2011) } .
{ '19-apr-2013' . (Date newDay:19 month:4 year:2013) } .
{ '21-may-2015' . (Date newDay:21 month:5 year:2015) } .
{ '21-jun-2015' . (Date newDay:21 month:6 year:2015) } .
{ '21-jul-2015' . (Date newDay:21 month:7 year:2015) } .
{ '21-aug-2015' . (Date newDay:21 month:8 year:2015) } .
{ '21-sep-2015' . (Date newDay:21 month:9 year:2015) } .
{ '21-oct-2015' . (Date newDay:21 month:10 year:2015) } .
{ '21-nov-2015' . (Date newDay:21 month:11 year:2015) } .
{ '21-dec-2015' . (Date newDay:21 month:12 year:2015) } .
} do:[:eachTestPair |
self assert:(Date
readFrom:(eachTestPair first)
printFormat:'%d-%shortMonthName-%y'
language:'en'
onError:[self error]
) = (eachTestPair second).
].
self assert:(Date
readFrom:'2-may-2010'
printFormat:'%d-%monthName-%y'
language:'en'
onError:[self error]
) = (Date newDay:2 month:5 year:2010).
self assert:(Date
readFrom:'2-may-2010'
printFormat:'%d-%(shortMonthName)-%y'
language:'en'
onError:[self error]
) = (Date newDay:2 month:5 year:2010).
self assert:(Date
readFrom:'2-may-2010'
printFormat:'%d-%(monthName)-%y'
language:'en'
onError:[self error]
) = (Date newDay:2 month:5 year:2010).
self assert:(Date
readFrom:'2-5-2010'
printFormat:'%d-%m-%y'
onError:[self error]
) = (Date newDay:2 month:5 year:2010).
self assert:(Date
readFrom:'5/2/2010'
printFormat:'%m/%d/%y'
onError:[self error]
) = (Date newDay:2 month:5 year:2010).
self assert:(Date
readFrom:'2010-5-2'
printFormat:'%y-%m-%d'
onError:[self error]
) = (Date newDay:2 month:5 year:2010).
"
self new test_02_ReadingDates
"
!
test_03_calenderWeek
self assert:(Date newDay:5 month:11 year:2012) weekInYear == 45.
self assert:(Date newDay:11 month:11 year:2012) weekInYear == 45.
self assert:(Date newDay:4 month:11 year:2012) weekInYear == 44.
self assert:(Date newDay:12 month:11 year:2012) weekInYear == 46.
self assert:(Date newDay:29 month:12 year:2014) weekInYear == 1. "/ YES!!
self assert:(Date newDay:30 month:12 year:2014) weekInYear == 1. "/ YES!!
self assert:(Date newDay:31 month:12 year:2014) weekInYear == 1. "/ YES!!
self assert:(Date newDay:1 month:1 year:2015) weekInYear == 1.
self assert:(Date newDay:2 month:1 year:2015) weekInYear == 1.
self assert:(Date newDay:3 month:1 year:2015) weekInYear == 1.
self assert:(Date newDay:4 month:1 year:2015) weekInYear == 1.
self assert:(Date newDay:5 month:1 year:2015) weekInYear == 2.
"/ every 4th of january is in the 1st week
1902 to:2100 do:[:y |
|d|
d := Date newDay:4 month:1 year:y.
self assert:d weekInYear == 1.
].
"
self new test_03_calenderWeek
"
!
test_04_calenderWeek_fails
<test: broken>
^ self.
"/ currently fails for date before 1901
1900 to:1905 do:[:y |
|d|
d := Date newDay:4 month:1 year:y.
self assert:d weekInYear == 1.
].
"
self new test_04_calenderWeek_fails
"
!
test_05_weekDayConversion
{
{ #( 6 53 2004) "2004-W53-6" . (Date newDay:1 month:1 year:2005) } .
{ #( 7 53 2004) "2004-W53-7" . (Date newDay:2 month:1 year:2005) } .
{ #( 6 52 2005) "2005-W52-6" . (Date newDay:31 month:12 year:2005) } .
{ #( 1 1 2007) "2007-W01-1" . (Date newDay:1 month:1 year:2007) } .
{ #( 7 52 2007) "2007-W52-7" . (Date newDay:30 month:12 year:2007) } .
{ #( 1 1 2008) "2008-W01-1" . (Date newDay:31 month:12 year:2007) } .
{ #( 2 1 2008) "2008-W01-2" . (Date newDay:1 month:1 year:2008) } .
{ #( 7 52 2008) "2008-W52-7" . (Date newDay:28 month:12 year:2008) } .
{ #( 1 1 2009) "2009-W01-1" . (Date newDay:29 month:12 year:2008) } .
{ #( 2 1 2009) "2009-W01-2" . (Date newDay:30 month:12 year:2008) } .
{ #( 3 1 2009) "2009-W01-3" . (Date newDay:31 month:12 year:2008) } .
{ #( 4 1 2009) "2009-W01-4" . (Date newDay:1 month:1 year:2009) } .
{ #( 4 53 2009) "2009-W53-4" . (Date newDay:31 month:12 year:2009) } .
{ #( 5 53 2009) "2009-W53-5" . (Date newDay:1 month:1 year:2010) } .
{ #( 6 53 2009) "2009-W53-6" . (Date newDay:2 month:1 year:2010) } .
{ #( 7 53 2009) "2009-W53-7" . (Date newDay:3 month:1 year:2010) } .
} do:[:eachPair |
|dwy d1 d2 dayInWeek weekNr year|
dwy := eachPair first.
dayInWeek := dwy first.
weekNr := dwy second.
year := dwy third.
d1 := Date newDayInWeek:dayInWeek week:weekNr year:year.
d2 := eachPair second.
self assert:(d1 = d2) description:'wrong: ',d1 printString, ' vs. ',d2 printString.
self assert:(d1 weekInYear == weekNr).
self assert:(d1 dayInWeek == dayInWeek).
]
"
self new test_05_weekDayConversion
"
!
test_06_readingISO8601
{
{ '2004-W53-6' . 'sat' . (Date newDay:1 month:1 year:2005) } .
{ '2004-W53-7' . 'sun' . (Date newDay:2 month:1 year:2005) } .
{ '2005-W52-6' . 'sat' . (Date newDay:31 month:12 year:2005) } .
{ '2007-W01-1' . 'mon' . (Date newDay:1 month:1 year:2007) } .
{ '2007-W52-7' . 'sun' . (Date newDay:30 month:12 year:2007) } .
{ '2008-W01-1' . 'mon' . (Date newDay:31 month:12 year:2007) } .
{ '2008-W01-2' . 'tue' . (Date newDay:1 month:1 year:2008) } .
{ '2008-W52-7' . 'sun' . (Date newDay:28 month:12 year:2008) } .
{ '2009-W01-1' . 'mon' . (Date newDay:29 month:12 year:2008) } .
{ '2009-W01-2' . 'tue' . (Date newDay:30 month:12 year:2008) } .
{ '2009-W01-3' . 'wed' . (Date newDay:31 month:12 year:2008) } .
{ '2009-W01-4' . 'thu' . (Date newDay:1 month:1 year:2009) } .
{ '2009-W53-4' . 'thu' . (Date newDay:31 month:12 year:2009) } .
{ '2009-W53-5' . 'fri' . (Date newDay:1 month:1 year:2010) } .
{ '2009-W53-6' . 'sat' . (Date newDay:2 month:1 year:2010) } .
{ '2009-W53-7' . 'sun' . (Date newDay:3 month:1 year:2010) } .
} do:[:eachTriple |
|input expected expectedDayName got gotName|
input := eachTriple first.
expectedDayName := eachTriple second.
expected := eachTriple third.
got := (Timestamp readIso8601FormatFrom:input onError:nil) asDate.
self assert:(got = expected) description:'wrong: ',input.
gotName := got abbreviatedDayNameForLanguage:#en.
self assert:gotName = expectedDayName description:'expected: ',expectedDayName asString,' got: ',gotName asString.
]
"
self new test_06_calenderWeek_fails
"
! !
!TimeAndDateTest class methodsFor:'documentation'!
version
^ '$Header$'
!
version_CVS
^ '$Header$'
! !