feat(store): add recur and recur_mode task fields

Problem: the task schema has no fields for storing recurrence rules.

Solution: add recur and recur_mode to the Task class, known_fields,
task_to_table, table_to_task, and the add() signature.
This commit is contained in:
Barrett Ruth 2026-02-25 13:03:40 -05:00
parent c2310f2659
commit e69e93f536
2 changed files with 50 additions and 1 deletions

View file

@ -7,6 +7,8 @@ local config = require('pending.config')
---@field category? string
---@field priority integer
---@field due? string
---@field recur? string
---@field recur_mode? 'scheduled'|'completion'
---@field entry string
---@field modified string
---@field end? string
@ -56,6 +58,8 @@ local known_fields = {
category = true,
priority = true,
due = true,
recur = true,
recur_mode = true,
entry = true,
modified = true,
['end'] = true,
@ -81,6 +85,12 @@ local function task_to_table(task)
if task.due then
t.due = task.due
end
if task.recur then
t.recur = task.recur
end
if task.recur_mode then
t.recur_mode = task.recur_mode
end
if task['end'] then
t['end'] = task['end']
end
@ -105,6 +115,8 @@ local function table_to_task(t)
category = t.category,
priority = t.priority or 0,
due = t.due,
recur = t.recur,
recur_mode = t.recur_mode,
entry = t.entry,
modified = t.modified,
['end'] = t['end'],
@ -224,7 +236,7 @@ function M.get(id)
return nil
end
---@param fields { description: string, status?: string, category?: string, priority?: integer, due?: string, order?: integer, _extra?: table }
---@param fields { description: string, status?: string, category?: string, priority?: integer, due?: string, recur?: string, recur_mode?: string, order?: integer, _extra?: table }
---@return pending.Task
function M.add(fields)
local data = M.data()
@ -236,6 +248,8 @@ function M.add(fields)
category = fields.category or config.get().default_category,
priority = fields.priority or 0,
due = fields.due,
recur = fields.recur,
recur_mode = fields.recur_mode,
entry = now,
modified = now,
['end'] = nil,