mirror of
https://github.com/TheRealOwenRees/plantid-discord-bot.git
synced 2026-07-23 04:26:57 +00:00
file server started in supervisor tree
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
# https://rosettacode.org/wiki/Convert_seconds_to_compound_duration
|
||||
defmodule PlantIdDiscordBot.Utils.Duration do
|
||||
@minute 60
|
||||
@hour @minute * 60
|
||||
@day @hour * 24
|
||||
@week @day * 7
|
||||
@divisor [@week, @day, @hour, @minute, 1]
|
||||
|
||||
def sec_to_str(sec) do
|
||||
{_, [s, m, h, d, w]} =
|
||||
Enum.reduce(@divisor, {sec, []}, fn divisor, {n, acc} ->
|
||||
{rem(n, divisor), [div(n, divisor) | acc]}
|
||||
end)
|
||||
|
||||
["#{w}w", "#{d}d", "#{h}h", "#{m}m", "#{s}s"]
|
||||
|> Enum.reject(fn str -> String.starts_with?(str, "0") end)
|
||||
|> Enum.join(" ")
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user