Skip to content

Commit

Permalink
feat: Add day count to the getTimeInWords function
Browse files Browse the repository at this point in the history
  • Loading branch information
omarcopires committed Apr 4, 2024
1 parent 167bae5 commit 434f20f
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 434f20f

Please sign in to comment.