John Joyce
3/14/2007 5:27:00 PM
I think we can honestly assume that if you are born on leap day, you
become highly tolerant of systems that don't even accept leap day
birthdays and probably write Feb 28 or Mar 1 consistently by habit.
On Mar 15, 2007, at 2:14 AM, Pit Capitain wrote:
> Brian Adkins schrieb:
>> Reid Thompson wrote:
>>> irb(main):001:0> require 'date'
>>> => true
>>> irb(main):002:0> bd = Date.new(1966, 1, 21)
>>> => #<Date: 4878293/2,0,2299161>
>>> irb(main):003:0> today = Date.new(2007,3,14)
>>> => #<Date: 4908347/2,0,2299161>
>>> irb(main):004:0> age = today.year - bd.year
>>> => 41
>> Consider when today.month < bd.month - you'll have an off-by-one
>> error.
>
> age -= 1 if today.month < bd.month || today.month == bd.month &&
> today.day < bd.day
>
> I don't know how people born at February 29th celebrate their
> birthday in non-leap years. The code above makes them one year
> older on March 1st.
>
> Regards,
> Pit
>
>