<html><head></head><body><div class="ydp9513f147yahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px;"><div><div dir="ltr" data-setdir="false">Just curious...</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">Has anyone thought about the "born on Feb 29" or "today's date is Feb 29" cases ?</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false">:)</div><div dir="ltr" data-setdir="false"><br></div><div dir="ltr" data-setdir="false"><br></div><div><br></div><div class="ydp9513f147signature"><div style="font-family:Helvetica, Arial, sans-serif;font-size:16px;">----------------- <br>BenoƮt St-Jean <br>Yahoo! Messenger: bstjean
<br>Twitter: @BenLeChialeux
<br>Pinterest: benoitstjean
<br>Instagram: Chef_Benito<br><div>IRC: lamneth <br></div><div>GitHub: bstjean<br></div>Blogue: endormitoire.wordpress.com
<br>"A standpoint is an intellectual horizon of radius zero". (A. Einstein)</div></div></div>
<div><br></div><div><br></div>
</div><div id="ydp718e39e0yahoo_quoted_4818598394" class="ydp718e39e0yahoo_quoted">
<div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
<div>
On Saturday, June 26, 2021, 12:59:38 p.m. EDT, David T. Lewis <lewis@mail.msen.com> wrote:
</div>
<div><br></div>
<div><br></div>
<div>On Sat, Jun 26, 2021 at 01:13:06PM +0200, Bal??zs K??si wrote:<br>> Ken's solution can be fixed for non-leap years by using <= instead of <,<br>> but it breaks down for leap years. e.g.<br>> <br>> a := Date year: 2003 month: 3 day: 1.<br>> b := Date year: 2004 month: 2 day: 29.<br>> <br>> b year - a year - (a dayOfYear <= b dayOfYear ifTrue: 0 ifFalse: 1) "<br>> outputs 1 "<br>> <br>> What seems to work is to let Date handle the leap year case with<br>> #addMonths:. e.g.<br>> <br>> yd := b year - a year.<br>> (a addMonths: 12 * yd) > b ifTrue: [ yd - 1 ] ifFalse: [ yd ]. " outputs 0 "<br>> Bal??zs<br>><br><br>Here is another variation that seems to work with leap years:<br> <br><br>Date ageAt: aDate<br> "Given a date representing a person's birthday, answer that person's age at<br> aDate as reported in the Western tradition. Note that age is reported differently<br> in India and possibly other cultures."<br><br> " '9 Aug 1984' asDate ageAt: Date today "<br><br> ^ (aDate monthIndex > self monthIndex<br> or: [aDate monthIndex = self monthIndex and: [aDate dayOfMonth >= self dayOfMonth]])<br> ifTrue: [aDate year - self year]<br> ifFalse: [aDate year - self year - 1].<br><br><br>It's a bit discouraging when I use this with my real birthday though ;-)<br><br>Dave<br><br><br></div>
</div>
</div></body></html>