## [squeak-dev] Chronology and birthdays/ages

Vanessa Freudenberg vanessa at codefrau.net
Sat Jun 26 01:25:51 UTC 2021

```That one is not quite correct for leap/non-leap years:

born := Date year: 1972 month: 5 day: 1.
today := Date year: 1978 month: 5 day: 1.
today year - born year - (born dayOfYear < today dayOfYear ifTrue: 0
ifFalse: 1)
=> 5

... but it should be the 6th birthday.

- Vanessa -

On Fri, Jun 25, 2021 at 3:05 PM Ken Causey <klcausey at gmail.com> wrote:

> Yes, the alternative is to get years as a float or fraction and truncate,
> but I think that would be a more costly calculation unless there is some
> trick to calculating the number of leap years between 2 years.
>
> On Fri, Jun 25, 2021 at 4:59 PM tim Rowledge <tim at rowledge.org> wrote:
>
>> Yeah, it's 'interesting' like all date related stuff. Leap years add some
>> extra joy.
>>
>> > On 2021-06-25, at 2:42 PM, Ken Causey <klcausey at gmail.com> wrote:
>> >
>> > This is the best I have managed, at least as a single line
>> >
>> > Date current year - (Date year: 1971 month: 1 day: 5) year - ((Date
>> year: 1971 month: 1 day: 5) dayOfYear < Date current dayOfYear ifTrue: 0
>> ifFalse: 1)
>> >
>> > This also works in Cuis.  Use of a variable for the birth date helps to
>> reduce repetition of course.
>> >
>> > Ken
>> >
>> > On Fri, Jun 25, 2021 at 2:30 PM tim Rowledge <tim at rowledge.org> wrote:
>> > I was just looking at calculating an age from birth date and 'test'
>> date and was startled to find no convenient method in the relevant classes.
>> Given how many things Chronology does I'm convinced I must have missed
>> sometihng obvious - but where?
>> >
>> > tim
>> > --
>> > tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
>> > Strange OpCodes: LD: Lose Device
>> >
>> >
>> >
>> >
>>
>>
>> tim
>> --
>> tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
>> "Bother" said Pooh as he said f**k in the wrong conf.
>>
>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20210625/d8f63e3c/attachment.html>
```