Created
July 11, 2015 18:00
-
-
Save max-power/29f740da75e0b46c1c56 to your computer and use it in GitHub Desktop.
Duration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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