Skip to content

Instantly share code, notes, and snippets.

@max-power
Created July 11, 2015 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save max-power/29f740da75e0b46c1c56 to your computer and use it in GitHub Desktop.
Save max-power/29f740da75e0b46c1c56 to your computer and use it in GitHub Desktop.
Duration
class Duration
attr_accessor :from, :till
def initialize(from: nil, till: nil)
@from = from || Time.now
@till = till || Time.now
end
def seconds
(till - from).round
end
def minutes
seconds / 60
end
def hours
minutes / 60
end
def days
hours / 24
end
def months
days / 30
end
def years
days / 365
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment