-
-
Save anonymous/f622df51ed55679f03af to your computer and use it in GitHub Desktop.
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 TimeDuration | |
def initialize(duration) | |
result = duration.match(/^(\d+)\s+(\w+)$/) | |
durations = { "day" => 60*60*24, "days" => 60*60*24, "min" => 60, "minute" => 60, "minutes" => 60, "hour" => 60*60, "hours" => 60*60, "week" => 60*60*24*7, "weeks" => 60*60*24*7, "year" => 60*60*24*365, "years" => 60*60*24*365 } | |
@duration = result[1].to_i * durations[result[2]] | |
end | |
def +(time_stamp) | |
time_stamp + @duration | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment