class: RegressionTests::TimeAndDateTest
added: #test_07_readingISO8601
changed: #test_05_weekDayConversion
more iso8601 reader tests
"{ 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) } .
{ #( 1 1 1997) "1997-W01-1" . (Date newDay:30 month:12 year:1996) } .
} 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
"
!
test_07_readingISO8601
{
{ '1995-02-20T13:11:06.123' . '1995-02-20 13:11:06.123' } .
{ '1995-02-20T13:11:06' . '1995-02-20 13:11:06.000' } .
{ '1995-02T13:11:06' . '1995-02-01 13:11:06.000' } .
{ '1995T13:11:06' . '1995-01-01 13:11:06.000' } .
{ '1995T13:11' . '1995-01-01 13:11:00.000' } .
{ '1995T13:11.5' . '1995-01-01 13:11:30.000' } .
{ '1995T13:11,5' . '1995-01-01 13:11:30.000' } .
{ '1995T13' . '1995-01-01 13:00:00.000' } .
{ '1995T13.25' . '1995-01-01 13:15:00.000' } .
{ '1995T13.333333' . '1995-01-01 13:19:59.999' } .
{ '1995' . '1995-01-01 00:00:00.000' } .
{ '1995-02' . '1995-02-01 00:00:00.000' } .
{ '19950204' . '1995-02-04 00:00:00.000' } .
"/ day in year
{ '1995-001' . '1995-01-01 00:00:00.000' } .
{ '1995-035' . '1995-02-04 00:00:00.000' } .
{ '1995035' . '1995-02-04 00:00:00.000' } .
{ '1997-01-01' . '1997-01-01 00:00:00.000' } .
"/ week and weekday
{ '1997-W01' . '1996-12-30 00:00:00.000' } .
{ '1997W01' . '1996-12-30 00:00:00.000' } .
{ '1997W01-1' . '1996-12-30 00:00:00.000' } .
{ '1997W011' . '1996-12-30 00:00:00.000' } .
{ '1997W01' . '1996-12-30 00:00:00.000' } .
{ '1997W01-2' . '1996-12-31 00:00:00.000' } .
{ '1997-W01-2' . '1996-12-31 00:00:00.000' } .
{ '1997W012' . '1996-12-31 00:00:00.000' } .
{ '2014W40' . '2014-09-29 00:00:00.000' } .
{ '2014W44-4' . '2014-10-30 00:00:00.000' } .
{ '2014W01' . '2013-12-30 00:00:00.000' } .
{ '2014W01-1' . '2013-12-30 00:00:00.000' } .
{ '2014W01-2' . '2013-12-31 00:00:00.000' } .
{ '2014W01-3' . '2014-01-01 00:00:00.000' } .
{ '1995-02-20 13:11' . '1995-02-20 13:11:00.000' } .
{ '1995-02-20 1311' . '1995-02-20 13:11:00.000' } .
{ '1995-02-20 13' . '1995-02-20 13:00:00.000' } .
{ '1995-02-20 235959' . '1995-02-20 23:59:59.000' } .
{ '19950220 235959' . '1995-02-20 23:59:59.000' } .
{ '19950220 23:59:59.9942' . '1995-02-20 23:59:59.994' } .
{ '19950220 235959.9942' . '1995-02-20 23:59:59.994' } .
"/ local vs. UTC
{ '1995-02-20 13:11:06' . '1995-02-20 13:11:06.000' } .
{ '1995-02-20 13:11:06Z' . '1995-02-20 13:11:06.000' } .
{ '1995-02-20 13:11:06+01' . '1995-02-20 12:11:06.000' } .
{ '1995-02-20 13:11:06+01:00' . '1995-02-20 12:11:06.000' } .
{ '1995-02-20 13:11:06+01:30' . '1995-02-20 11:41:06.000' } .
{ '1995-02-20 13:11:06+0130' . '1995-02-20 11:41:06.000' } .
{ '1995-02-20 13:11:06-01' . '1995-02-20 14:11:06.000' } .
{ '1995-02-20 13:11:06-01:00' . '1995-02-20 14:11:06.000' } .
{ '1995-02-20 13:11:06-01:30' . '1995-02-20 14:41:06.000' } .
{ '1995-02-20 13:11:06-0130' . '1995-02-20 14:41:06.000' } .
"/ 24 is allowed with ISO, and is 00:00 of the next day:
{ '1995-02-20 24:00:00' . '1995-02-21 00:00:00.000' } .
} do:[:eachPair |
|s1 d s|
s1 := eachPair first.
d := UtcTimestamp readIso8601FormatFrom:s1.
s := eachPair second.
self assert:(d asString = s) description:'expected: ',s,' got:',d printString.
].
"
self new test_07_readingISO8601
"
! !
!TimeAndDateTest class methodsFor:'documentation'!
version
^ '$Header$'
!
version_CVS
^ '$Header$'
! !