feat(parse): add parse_duration_to_days for duration string conversion

Problem: The archive command accepted only a bare integer for days,
inconsistent with the `+Nd`/`+Nw`/`+Nm` duration syntax used elsewhere.

Solution: Add `parse_duration_to_days()` supporting `Nd`, `Nw`, `Nm`,
and bare integers. Returns nil on invalid input for caller error handling.
This commit is contained in:
Barrett Ruth 2026-03-08 20:25:22 -04:00
parent c5d55e5e92
commit 8cfdafe464
2 changed files with 67 additions and 0 deletions

View file

@ -667,4 +667,29 @@ function M.is_today(due)
return time_part >= current_time
end
---@param s? string
---@return integer?
function M.parse_duration_to_days(s)
if s == nil or s == '' then
return nil
end
local n = s:match('^(%d+)d$')
if n then
return tonumber(n) --[[@as integer]]
end
n = s:match('^(%d+)w$')
if n then
return tonumber(n) --[[@as integer]] * 7
end
n = s:match('^(%d+)m$')
if n then
return tonumber(n) --[[@as integer]] * 30
end
n = s:match('^(%d+)$')
if n then
return tonumber(n) --[[@as integer]]
end
return nil
end
return M