Initial commit
This commit is contained in:
18
app/helpers/duration_helper.rb
Normal file
18
app/helpers/duration_helper.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
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
|
||||
Reference in New Issue
Block a user