From c64ae508d158dec51f8de8ed468601b73daa61a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 23 Aug 2009 02:45:15 +0200 Subject: speed up ? age --- lib/ayk/age.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/ayk/age.rb b/lib/ayk/age.rb index fc1aeb3..0ecc40e 100644 --- a/lib/ayk/age.rb +++ b/lib/ayk/age.rb @@ -18,12 +18,17 @@ class DateTime return [nil]*6 if at>(12*years) ) > at x = self>>(12*years) - # months - months = at.month-x.month+(12*(at.year-x.year)) - months -= 1 if ( x>>months ) > at + if x>at + years -= 1 + x<<=12 + end + months = at.month-x.month+(11*(at.year-x.year)) x >>=months + if x>at + months -= 1 + x <<=1 + end # days days = (at-x).to_i x += days -- cgit v1.1-2-g2b99