[squeak-dev] Chronology and birthdays/ages

Balázs Kósi rebmekop at gmail.com
Sat Jun 26 11:13:06 UTC 2021


Ken's solution can be fixed for non-leap years by using <= instead of <,
but it breaks down for leap years. e.g.

a := Date year: 2003 month: 3 day: 1.
b := Date year: 2004 month: 2 day: 29.

b year - a year - (a dayOfYear <= b dayOfYear ifTrue: 0 ifFalse: 1) "
outputs 1 "

What seems to work is to let Date handle the leap year case with
#addMonths:. e.g.

yd := b year - a year.
(a addMonths: 12 * yd) > b ifTrue: [ yd - 1 ] ifFalse: [ yd ]. " outputs 0 "
Balázs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20210626/2b11e3cf/attachment.html>


More information about the Squeak-dev mailing list