format time in logo

This commit is contained in:
metamuffin 2024-11-03 22:34:04 +01:00
parent f71092470d
commit 9f453051c7
No known key found for this signature in database
GPG key ID: 718F9749DCDBD654

View file

@ -167,30 +167,21 @@ local function last_txns()
end end
local function get_active_users() local function get_active_users()
local user_balances = {} local user_balances = {}
for time, username, amount, _, _, _ in read_log() do for time, username, amount, _, _, _ in read_log() do
user_balances[username] = { user_balances[username] = {
time = time, time = time,
username = username, username = username,
balance = (user_balances[username] or {balance = 0}).balance + amount balance = (user_balances[username] or { balance = 0 }).balance + amount
} }
end end
local users = {} local users = {}
for _, user in pairs(user_balances) do for _, user in pairs(user_balances) do
table.insert(users, user) table.insert(users, user)
end end
table.sort(users, function(a,b) return a.time > b.time end) table.sort(users, function(a, b) return a.time > b.time end)
for k, user in pairs(users) do
io.stderr:write(string.format("%s %s %s %s\n",
k,
os.date("!%Y-%m-%dT%H:%M:%SZ", user.time),
user.username,
user.balance
))
end
return users return users
end end
@ -210,7 +201,8 @@ local function r_user_post(username)
pcount = (tonumber(data.pcount) or 1) * (data.negate_pcount ~= nil and -1 or 1) pcount = (tonumber(data.pcount) or 1) * (data.negate_pcount ~= nil and -1 or 1)
pcode = p_barcode pcode = p_barcode
if amount == nil then amount = pcount * p_amount end if amount == nil then amount = pcount * p_amount end
if comment == nil then comment = string.format("%s %d %s", pcount < 0 and "Buy" or "Restock", math.abs(pcount), p_name) end if comment == nil then comment = string.format("%s %d %s", pcount < 0 and "Buy" or "Restock",
math.abs(pcount), p_name) end
end end
end end
if amount == nil then if amount == nil then
@ -331,7 +323,7 @@ local function r_log(filter)
if filter == nil or filter == username then if filter == nil or filter == username then
print(string.format([[ print(string.format([[
<tr> <tr>
<td>%d (%s ago)</td> <td>%s (%s ago)</td>
<td>%s</td> <td>%s</td>
<td class="amount-%s">%.02f</td> <td class="amount-%s">%.02f</td>
<td>%s</td> <td>%s</td>
@ -346,7 +338,7 @@ local function r_log(filter)
</td> </td>
</tr> </tr>
]], ]],
time, format_duration(os.time() - time), os.date("!%Y-%m-%dT%H:%M:%SZ", time), format_duration(os.time() - time),
escape(username), escape(username),
amount >= 0 and "pos" or "neg", amount / 100, amount >= 0 and "pos" or "neg", amount / 100,
escape(pcode) or "", escape(pcode) or "",
@ -373,7 +365,7 @@ local function r_index()
</form> </form>
]]) ]])
print("<ul>") print("<ul>")
for _, user in ipairs(get_active_users()) do for _, user in ipairs(get_active_users()) do
print(string.format([[ print(string.format([[
<li><a href="/%s"><span class="name">%s</span> <span class="amount amount-%s">%.02f</span></a></li> <li><a href="/%s"><span class="name">%s</span> <span class="amount amount-%s">%.02f</span></a></li>