As an aside - there is another way of doing it - but I’m not sure if its 
clearer (or more efficient):

^ ((aDate year * 10000 + (aDate monthIndex * 100) + aDate dayOfMonth
                - (self year * 10000 + (self monthIndex * 100) + self 
dayOfMonth)) / 10000) truncated


> On 21 Jul 2017, at 12:54, K K Subbu <kksubbu...@gmail.com> wrote:
> 
> On Friday 21 July 2017 03:01 PM, Tim Mackinnon wrote:
>> Actually that simplification doesn’t work - someone born on 1/Mar/2000 
>> should be 11 on 1/Mar/2011 and this answers 10 (the previous version did 
>> work).
> 
> You're right. The simplification does not take into account leap days. Mea 
> culpa. Original code (dropping +1) is readable and simple.
> 
> Regards .. Subbu
> 
>> This does make me think its tricky enough to put this in the core - I may 
>> submit it along with the unit tests I borrowed from Stack Overflow (the 
>> shame)…
>> Its a good problem though. Thanks for discussing it with me.
>> Tim
>>> On 21 Jul 2017, at 10:09, K K Subbu <kksubbu...@gmail.com 
>>> <mailto:kksubbu...@gmail.com>> wrote:
>>> 
>>> ^aDate year - self year -
>>> (aDate dayOfYear < self dayOfYear) ifTrue: [ 1 ] ifFalse: [ 0 ])
> 
> 


Reply via email to