summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ayk/age.rb13
1 files 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<self
# years
years = at.year-self.year
- years -= 1 if ( self>>(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