Skip to content

Instantly share code, notes, and snippets.

@FiXato
Created January 2, 2013 00:17
Show Gist options
  • Save FiXato/4431214 to your computer and use it in GitHub Desktop.
Save FiXato/4431214 to your computer and use it in GitHub Desktop.
A Ruby tool to calculate the amount of years, days or hours+minutes on Earth since a date of birth.
#!/usr/bin/env ruby
# encoding: utf-8
require 'rubygems'
require 'chronic'
require 'date'
if ARGV.size > 0
dob = Chronic.parse(ARGV.join(' '))
strings = ['You were', 'you']
else
dob = Chronic.parse('01 january 1970 at 20:12 GMT+1')
strings = ['I was', 'me']
end
time_since = DateTime.now - dob.__send__(:to_date)
def day_fraction_to_time(fr)
h, fr = fr.divmod(1.to_r/24)
min, fr = fr.divmod(1.to_r/1440)
s, fr = fr.divmod(1.to_r/86400)
return h, min, s, fr
end
hours, minutes, seconds, frac = day_fraction_to_time(time_since)
total_minutes = (minutes + 60 * hours)
puts "#{strings[0]} born #{'%0.2f' % time_since} Terran days, or #{hours} hours and roughly #{minutes} minutes ago. This makes #{strings[1]} about #{total_minutes} minutes (or about #{'%0.2f' % (total_minutes / 525949.2)} Terran years) old"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment