37 lines
1.1 KiB
Lua
37 lines
1.1 KiB
Lua
|
|
-- Sum of today's expenses (local calendar day).
|
||
|
|
|
||
|
|
local lang = jarvis.context.language
|
||
|
|
local raw_state = jarvis.state.get("entries") or ""
|
||
|
|
|
||
|
|
if raw_state == "" then
|
||
|
|
return jarvis.cmd.not_found(lang == "ru"
|
||
|
|
and "Сегодня ничего не тратили, сэр."
|
||
|
|
or "No expenses logged today, sir.")
|
||
|
|
end
|
||
|
|
|
||
|
|
local now = jarvis.context.time
|
||
|
|
local day_start = os.time({
|
||
|
|
year = now.year, month = now.month, day = now.day,
|
||
|
|
hour = 0, min = 0, sec = 0,
|
||
|
|
})
|
||
|
|
local day_end = day_start + 86400
|
||
|
|
|
||
|
|
local total = 0
|
||
|
|
for chunk in raw_state:gmatch("([^|]+)") do
|
||
|
|
local ts, am = chunk:match("^(%d+),([%-%d%.]+),")
|
||
|
|
ts = tonumber(ts); am = tonumber(am)
|
||
|
|
if ts and am and ts >= day_start and ts < day_end then
|
||
|
|
total = total + am
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
if total == 0 then
|
||
|
|
return jarvis.cmd.ok(lang == "ru"
|
||
|
|
and "Сегодня ничего не тратили, сэр."
|
||
|
|
or "Nothing spent today, sir.")
|
||
|
|
end
|
||
|
|
|
||
|
|
return jarvis.cmd.ok(string.format(lang == "ru"
|
||
|
|
and "Сегодня потратили %.0f."
|
||
|
|
or "Today's spending: %.0f.", total))
|