This continues to be a fascination little problem with many angles and 
solutions.

Tim

Sent from my iPhone

> On 28 Jul 2017, at 21:31, PBKResearch <pe...@pbkresearch.co.uk> wrote:
> 
> Julián
>  
> Sorry, I should have checked my facts before sounding off. I think defining 
> dayOfMonth in the way you show is very counter-intuitive, but that is the 
> definition and I should have checked.
>  
> From: Pharo-users [mailto:pharo-users-boun...@lists.pharo.org] On Behalf Of 
> Julián Maestri
> Sent: 28 July 2017 17:40
> To: Any question about pharo is welcome <pharo-users@lists.pharo.org>
> Subject: Re: [Pharo-users] How to calculate someone's age elegantly? Does 
> Duration work?
>  
> It still works, probably because dayOfMonth is not what you expected at first 
> glance.
>  
> For a date, you have 3 accessors, and i think you were expecting #dayNumber
>  
> (January third, 1990) day. "Wednesday".
> (January third, 1990) dayOfMonth. "January 3"
> (January third, 1990) dayNumber. "3"
>  
>  
>  
> On 27 July 2017 at 16:43, PBKResearch <pe...@pbkresearch.co.uk> wrote:
> Julián
>  
> I don’t know Chalten, but I wonder whether your definition of Person>>ageOn: 
> will work correctly. Could I suggest you add two extra assertions to your 
> test:
>  
> assert: (john ageOn: February fifteenth , 2013) equals: (TimeUnits year with: 
> 49);
> assert: (john ageOn: April first , 2013) equals: (TimeUnits year with: 50);
>  
> Clearly these should be true, but I think they will not be – unless 
> Date>>dayOfMonth works in a very counter-intuitive way.
>  
> HTH
>  
> Peter Kenny
>  
>  
> From: Pharo-users [mailto:pharo-users-boun...@lists.pharo.org] On Behalf Of 
> Julián Maestri
> Sent: 27 July 2017 18:58
> To: Any question about pharo is welcome <pharo-users@lists.pharo.org>
> Subject: Re: [Pharo-users] How to calculate someone's age elegantly? Does 
> Duration work?
>  
> Using https://github.com/ba-st/Chalten the solution was something like this:
>  
> Person>>ageOn: aDate
>   | difference |
>   difference := (aDate year distanceFrom: self dateOfBirth year).
>   ^(aDate dayOfMonth < self dateOfBirth dayOfMonth)
>     ifTrue: [difference - TimeUnits year unitaryMeasurement]
>     ifFalse: [difference]
> Test for that
> testAge
> | john |
> john := Person namedFirst: 'John' last: 'Doe' born: March fourteenth , 1963.
> self
> assert: (john ageOn: March thirteenth , 2013) equals: (TimeUnits year with: 
> 49);
> assert: (john ageOn: March fourteenth , 2013) equals: (TimeUnits year with: 
> 50);
> assert: (john ageOn: March fifteenth , 2013) equals: (TimeUnits year with: 
> 50) 
>  
> On 21 July 2017 at 14:25, Tim Mackinnon <tim@testit.works> wrote:
> Paul - this is very helpful, gosh you learn a lot from what seemed like 
> simple question.
> 
> Your suggestion along with Subbu’s gives an easy workable solution - I also 
> wonder if the method should be in the image along with the comment explaining 
> half open intervals like you have. Do you think there is another name for 
> that end method - displayEnd sounds like it actively displays - I wonder if 
> boundedEnd or completeEnd or finiteEnd might be correct alternatives (or is 
> displayEnd a decent convention that everyone understands?)
> 
> I really have to learn how to submit pull requests (although it seems rather 
> complicated at the moment while the full git integration process is being 
> sorted out).
> 
> Thanks everyone
> 
> Tim
> 
> > On 21 Jul 2017, at 16:40, Paul DeBruicker <pdebr...@gmail.com> wrote:
> >
> > Tim Mackinnon wrote
> >> I am also wondering if the issue with Timespan is concerning - I was
> >> surprised that putting a start and end date left me something that didn’t
> >> answer my end date presumably down to rounding when it’s converted down to
> >> a duration (making me wonder if its better to keep a start and end date
> >> and calculate the duration on the fly).
> >>
> >> Tim
> >
> >
> > The Timespans are half open intervals.
> > (https://en.wikipedia.org/wiki/Interval_(mathematics))
> >
> > Friday July 21st ends at 11:59:59.99999999999... etc etc etc ...9999PM and
> > the 22nd starts at 12:00AM
> >
> >
> > If Timespans were closed intervals like you expect then we'd be out of whack
> > with our corner of the universe.  That extra clock tick adds complexity.
> >
> > But I add a method to my image called #displayEnd because I also want them
> > to print 3PM-4PM and not 3PM-3:59:59.999999999PM and use that in my print
> > statements and rendering for Seaside.
> >
> > displayEnd
> >       ^ start + duration
> >
> >
> >
> >
> >
> >
> >
> >
> > --
> > View this message in context: 
> > http://forum.world.st/How-to-calculate-someone-s-age-elegantly-Does-Duration-work-tp4955990p4956114.html
> > Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
> >
> 
>  
>  

Reply via email to