diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2009-08-23 02:45:15 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2011-06-30 08:04:46 +0200 |
commit | c64ae508d158dec51f8de8ed468601b73daa61a9 (patch) | |
tree | a0d2f070fda8680399945cc70f24978e3e360677 /lib | |
parent | 847cb204b3081c485d19bae31c83c561bd416956 (diff) | |
download | ayk-c64ae508d158dec51f8de8ed468601b73daa61a9.zip ayk-c64ae508d158dec51f8de8ed468601b73daa61a9.tar.gz |
speed up ? age
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ayk/age.rb | 13 |
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 |