Slide 32
Slide 32 text
module ActiveSupport
class Duration
SECONDS_PER_MINUTE = 60
SECONDS_PER_HOUR = 3600
SECONDS_PER_DAY = 86400
SECONDS_PER_WEEK = 604800
SECONDS_PER_MONTH = 2629746 # 1/12 of a gregorian year
SECONDS_PER_YEAR = 31556952 # length of a gregorian year (365.2425 days)
class << self
def seconds(value)
new(value, [[:seconds, value]])
end
def minutes(value)
new(value * SECONDS_PER_MINUTE, [[:minutes, value]])
end
def hours(value)
new(value * SECONDS_PER_HOUR, [[:hours, value]])
end
def days(value)
new(value * SECONDS_PER_DAY, [[:days, value]])
end
def weeks(value)
new(value * SECONDS_PER_WEEK, [[:weeks, value]])
end
def months(value)
new(value * SECONDS_PER_MONTH, [[:months, value]])
end
def years(value)
new(value * SECONDS_PER_YEAR, [[:years, value]])
end
end
end
end