Skip to content

Commit

Permalink
feat: include day count in getTimeInWords function (#2525)
Browse files Browse the repository at this point in the history
  • Loading branch information
omarcopires authored Apr 25, 2024
1 parent 0f91db0 commit 13798e5
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions data/libs/functions/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,38 @@ end

function getTimeInWords(secsParam)
local secs = tonumber(secsParam)
local days = math.floor(secs / (24 * 3600))
secs = secs - (days * 24 * 3600)
local hours, minutes, seconds = getHours(secs), getMinutes(secs), getSeconds(secs)
local timeStr = ""

if days > 0 then
timeStr = days .. (days > 1 and " days" or " day")
end

if hours > 0 then
timeStr = hours .. (hours > 1 and " hours" or " hour")
if timeStr ~= "" then
timeStr = timeStr .. ", "
end

timeStr = timeStr .. hours .. (hours > 1 and " hours" or " hour")
end

if minutes > 0 then
if timeStr ~= "" then
timeStr = timeStr .. ", "
end

timeStr = timeStr .. minutes .. (minutes > 1 and " minutes" or " minute")
end

if seconds > 0 then
if timeStr ~= "" then
timeStr = timeStr .. " and "
end

timeStr = timeStr .. seconds .. (seconds > 1 and " seconds" or " second")
end

return timeStr
end

Expand Down

0 comments on commit 13798e5

Please sign in to comment.