J.A.R.V.I.S-rust/resources/commands/date_math/days_until.lua

75 lines
2.6 KiB
Lua
Raw Permalink Normal View History

feat: GUI /memory page + disk/date_math/sleep_timer packs (10 new commands) GUI: Memory management completes the management trio (/macros + /scheduler + /memory). Tauri commands (crates/jarvis-gui/src/tauri_commands/memory.rs) - memory_list → Vec<MemoryFact{key, value, created_at, last_used_at, use_count}> - memory_remember(k, v) → persist new fact (or overwrite) - memory_forget(key) → delete by exact key - memory_search(q, limit) → substring search GUI /memory page (frontend/src/routes/memory/index.svelte) - Top: add-fact form (key + value inputs + "+Добавить" button) - Substring filter input for the list - Per-card: key + use_count badge + value (highlighted box) + timestamps + "Забыть" button with confirm() guard - Auto-sorted by recency (last_used_at desc) - Empty state shows voice-hint: 'скажи Jarvis-у "запомни что я люблю чай улун"' Header (frontend/src/components/Header.svelte) - New "Память" button between /scheduler and /settings. - i18n: header-memory in ru/en/ua FTL files. New voice packs resources/commands/disk/ (2 cmds) - disk.free "сколько свободно на диске" / "сколько места на диске C" PowerShell Get-PSDrive → speaks "Свободно X ГБ из Y, это N%" - disk.list "какие у меня диски" → "C 120 ГБ, D 300 ГБ, E 50 ГБ" resources/commands/date_math/ (2 cmds) - date.days_until "сколько дней до нового года" / "сколько до 8 марта" / "сколько до 15 марта" — recognises Russian months, holidays (Новый год, Рождество, 8 марта, 9 мая). Auto-rolls to next year if target already passed. Russian-grammar pluralisation (день/дня/дней). - date.day_of_week "какой сегодня день недели" — Zeller's congruence, maps to ru day name. resources/commands/sleep_timer/ (3 cmds) - sleep_timer.pause_in "выключи музыку через 30 минут" → scheduler one-shot lua action that fires media VK_MEDIA_PLAY_PAUSE via the existing media_keys helper. (Auto-generates _fire_pause.lua wrapper if missing.) - sleep_timer.shutdown_in "выключи компьютер через 1 час" → shutdown.exe /s /t <secs>. Caps at 24 hours. Speaks "Скажите 'отмени таймер' чтобы передумать." - sleep_timer.cancel "отмени таймер выключения" / "не выключай компьютер" → shutdown /a + scheduler.remove("sleep_timer_pause"), idempotent. Pack count: 64 → 67. Tests: 112/112 pass. Build: cargo build --release -p jarvis-gui green.
2026-05-15 23:35:23 +03:00
-- "Сколько дней до нового года" / "сколько до 15 марта"
local phrase = (jarvis.context.phrase or ""):lower()
local t = jarvis.context.time
local current_year = t.year
local MONTHS = {
["январ"]=1, ["феврал"]=2, ["март"]=3, ["апрел"]=4, ["май"]=5, ["мая"]=5, ["июн"]=6,
["июл"]=7, ["август"]=8, ["сентябр"]=9, ["октябр"]=10, ["ноябр"]=11, ["декабр"]=12,
}
-- Special phrases
local target_y, target_m, target_d
if phrase:find("нов") and phrase:find("год") then
target_y, target_m, target_d = current_year + 1, 1, 1
if t.month == 1 and t.day == 1 then target_y = current_year end
elseif phrase:find("рожд") then
target_y, target_m, target_d = current_year, 1, 7 -- ru orthodox
elseif phrase:find("8 март") or phrase:find("восьмого март") then
target_y, target_m, target_d = current_year, 3, 8
elseif phrase:find("9 ма") or phrase:find("девятое ма") then
target_y, target_m, target_d = current_year, 5, 9
end
-- Generic "до N <месяц>"
if not target_y then
local d = tonumber(phrase:match("до%s+(%d+)"))
if d then
for stem, month in pairs(MONTHS) do
if phrase:find(stem) then
target_d, target_m, target_y = d, month, current_year
break
end
end
end
end
if not target_y then
return jarvis.cmd.error("Не понял дату.")
end
-- If target this year already passed, jump to next year
local function days_since_epoch(y, m, d)
-- approximate: works for diffs within ~100 years
local total = y * 365 + math.floor(y / 4) - math.floor(y / 100) + math.floor(y / 400)
local cum = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }
total = total + cum[m] + (d - 1)
-- leap-day adjustment
local leap = (y % 4 == 0 and y % 100 ~= 0) or (y % 400 == 0)
if leap and m > 2 then total = total + 1 end
return total
end
local now = days_since_epoch(t.year, t.month, t.day)
local target = days_since_epoch(target_y, target_m, target_d)
if target < now then
target_y = target_y + 1
target = days_since_epoch(target_y, target_m, target_d)
end
local diff = target - now
if diff == 0 then
return jarvis.cmd.ok("Сегодня.")
end
-- Russian grammar: 1 день, 2-4 дня, 5+ дней
local last = diff % 10
local unit = "дней"
if last == 1 and diff % 100 ~= 11 then unit = "день"
elseif last >= 2 and last <= 4 and (diff % 100 < 10 or diff % 100 >= 20) then unit = "дня"
end
return jarvis.cmd.ok(string.format("%d %s.", diff, unit))