Hmmm to compound my woes ) I notice that Timespan is broken - as the following fails: testEndDateIsPreserved | startDate endDate | startDate := Date year: 2000 month: 2 day: 28. endDate := Date year: 2011 month: 2 day: 27. self assert: (Timespan starting: startDate ending: endDate) end equals: endDate.
On 21 Jul 2017, at 00:58, Tim Mackinnon <tim@testit.works> wrote:
Hi - I just ran a great MobProgramming session with Smalltalk for the XProLo group - and there was lots of great feedback and questions, however one of them really got me thinkingâ¦
We did a little exercise to create a Person class with name, dob - and then we TDDâd an age method⦠which seems simple on the surface but it gets to an interesting point - what about leap years? How old is someone on those years?
I thought that our plethora of Date/Duration classes might handle this - but I couldnât spot something obvious and was wondering if someone had a neat answer.
Essentially if you try:
age
^Date today - self dob
You get a Duration,
But there isnât :
^(Date today - self dob) asYears
There is is asDay
^(Date today - self dob) asDays
But then can you really
^(Date today - self dob) asDays / 365) truncated
But what about leap years⦠so
^(Date today - self dob) asDays / 365.25) truncated
It all feels a bit inelegant and I suspect there is a better Smalltalk way that is eluding me? Any suggestions?
Tim