Le 09/12/2014 02:15, Chris Muller a écrit :
>> I was working on a GenericYear that was intended to be used for DateAndTime
>> calculus - to be able to add and subtract an arbitrary number of years.  The
>> class by itself would not know the days - it is an arbitrary (generic) Year.
>>
>> It would only know the number of days when it is added (or subtracted) from
>> an actual date (or timespan).  The idea was that it would have a very
>> specific and limited scope of responsibility.
> 
> I liked it.  Hopefully a few loose ends can be fixed up so it can be
> put into trunk.
> 
> 

This one should be better

addYears: integer
        ^ Date
                year: self year + integer
                month: self monthIndex
                day: ((self monthIndex = 2
                        and: [self dayOfMonth = 29
                        and: [(Year isLeapYear: self year)
                        and: [(Year isLeapYear: self year + integer) not ]]])
                                ifTrue: [ 28 ]
                                ifFalse: [ self dayOfMonth])

-- 
Dr. Geo - http://drgeo.eu
iStoa - http://istoa.drgeo.eu


Reply via email to