Files
old-holivud2/app/helpers/duration_helper.rb

19 lines
647 B
Ruby
Raw Normal View History

2020-05-31 22:38:19 +02:00
module DurationHelper
MINUTES_IN_HOUR = 60
SECONDS_IN_MINUTE = 60
def convert_duration(value, from:, to:)
value_in_seconds = case from.to_s
when "seconds" then value
when "minutes" then value * SECONDS_IN_MINUTE
when "hours" then value * SECONDS_IN_MINUTE * MINUTES_IN_HOUR
end
result = case to.to_s
when "seconds" then value_in_seconds
when "minutes" then value_in_seconds / SECONDS_IN_MINUTE
when "hours" then value_in_seconds / SECONDS_IN_MINUTE / MINUTES_IN_HOUR
end
end
end