diff options
author | metamuffin <metamuffin@disroot.org> | 2024-11-03 22:34:04 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-11-03 22:52:27 +0100 |
commit | 9f453051c73afeeae9be3a210c1b76ec6fd9b015 (patch) | |
tree | 8d362c4b678b1339d20e695c296b0afeb2066f1c | |
parent | f71092470db660252450b12c5dbd9f74d9996664 (diff) | |
download | abrechenbarkeit-9f453051c73afeeae9be3a210c1b76ec6fd9b015.tar abrechenbarkeit-9f453051c73afeeae9be3a210c1b76ec6fd9b015.tar.bz2 abrechenbarkeit-9f453051c73afeeae9be3a210c1b76ec6fd9b015.tar.zst |
format time in logo
-rwxr-xr-x | abrechenbarkeit.lua | 38 |
1 files changed, 15 insertions, 23 deletions
diff --git a/abrechenbarkeit.lua b/abrechenbarkeit.lua index 77d7fd0..9244484 100755 --- a/abrechenbarkeit.lua +++ b/abrechenbarkeit.lua @@ -167,30 +167,21 @@ local function last_txns() end local function get_active_users() - local user_balances = {} + local user_balances = {} for time, username, amount, _, _, _ in read_log() do user_balances[username] = { - time = time, - username = username, - balance = (user_balances[username] or {balance = 0}).balance + amount + time = time, + username = username, + balance = (user_balances[username] or { balance = 0 }).balance + amount } end - local users = {} - for _, user in pairs(user_balances) do - table.insert(users, user) - 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 - + local users = {} + for _, user in pairs(user_balances) do + table.insert(users, user) + end + + table.sort(users, function(a, b) return a.time > b.time end) return users 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) pcode = p_barcode 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 if amount == nil then @@ -331,7 +323,7 @@ local function r_log(filter) if filter == nil or filter == username then print(string.format([[ <tr> - <td>%d (%s ago)</td> + <td>%s (%s ago)</td> <td>%s</td> <td class="amount-%s">%.02f€</td> <td>%s</td> @@ -346,7 +338,7 @@ local function r_log(filter) </td> </tr> ]], - time, format_duration(os.time() - time), + os.date("!%Y-%m-%dT%H:%M:%SZ", time), format_duration(os.time() - time), escape(username), amount >= 0 and "pos" or "neg", amount / 100, escape(pcode) or "", @@ -373,7 +365,7 @@ local function r_index() </form> ]]) print("<ul>") - + for _, user in ipairs(get_active_users()) do print(string.format([[ <li><a href="/%s"><span class="name">%s</span> <span class="amount amount-%s">%.02f€</span></a></li> |