mirror of
https://github.com/mt-mods/mail.git
synced 2025-07-17 19:56:37 -04:00
Add a tooltip for elapsed time since the delivery
It adds the file util/time_ago.lua in order to re-use the function further
This commit is contained in:
parent
fbdaaeec11
commit
37fad48ec8
11 changed files with 239 additions and 144 deletions
29
util/time_ago.lua
Normal file
29
util/time_ago.lua
Normal file
|
@ -0,0 +1,29 @@
|
|||
-- translation
|
||||
local S = minetest.get_translator("mail")
|
||||
|
||||
function mail.time_ago(t)
|
||||
local elapsed = os.time() - t
|
||||
local str = ""
|
||||
|
||||
local time_units = {
|
||||
{ S("years"), 31536000 },
|
||||
{ S("months"), 2592000 },
|
||||
{ S("weeks"), 604800 },
|
||||
{ S("days"), 86400 },
|
||||
{ S("hours"), 3600 },
|
||||
{ S("minuts"), 60 },
|
||||
{ S("seconds"), 1 },
|
||||
}
|
||||
|
||||
for _, u in ipairs(time_units) do
|
||||
local n = math.modf(elapsed/u[2])
|
||||
if n > 0 then
|
||||
str = str .. " " .. n .. " " .. u[1]
|
||||
elapsed = elapsed - n * u[2]
|
||||
end
|
||||
end
|
||||
|
||||
str = string.sub(str, 2, -1)
|
||||
|
||||
return S("@1 ago", str)
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue