Sum clocked times in a task
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
No repository files or tests are named in the issue. Start by locating the existing clock mode and Agenda rendering entry points, then compare their behavior with the supplied Lua function. Confirm where a task-level total should appear and add coverage for multiple clock entries, including totals spanning more than 24 hours.
Written by the indexing model from the issue text.
Description
Does this feature exist in Emacs orgmode core?
N/A
Orgmode link
No response
Feature value
It's nice to be able to see the clocked time of a task. Currently the sums per task are displayed in the Agenda view if the clock mode is active. But if a task spans days/weeks/months and has many clocked times it's difficult to sum them all up.
I used Gemini to create this function and integrated it into my functions.lua and it works great 🚀
Here's the function:
local function parse_duration_to_seconds(duration_str)
local hours, minutes = duration_str:match("^(%d+):(%d+)$")
if not hours or not minutes then return 0 end
local h = tonumber(hours)
local m = tonumber(minutes)
return (h * 3600) + (m * 60)
end
local function format_seconds_to_duration(total_seconds)
local total_minutes = math.floor(total_seconds / 60)
local hours = math.floor(total_minutes / 60)
local minutes = total_minutes % 60
return string.format("%d:%02d", hours, minutes)
end
function ClockSumSelectedLines()
local total_seconds = 0
local count = 0
local start_line = vim.fn.line("'<")
local end_line = vim.fn.line("'>")
-- Safety check for selection or single line
if start_line > end_line then
start_line = vim.fn.line(".")
end_line = vim.fn.line(".")
end
-- Get the content of the selected lines (start is 1-indexed, so we use start_line - 1)
local lines = vim.api.nvim_buf_get_lines(0, start_line - 1, end_line, false)
-- 1. Determine Indent from the first line
local first_line = lines[1] or ""
-- Lua pattern: ^(%s*) captures all leading whitespace at the start of the line.
local indent = first_line:match("^(%s*)") or ""
-- 2. Calculate Sum
for _, line in ipairs(lines) do
local duration = line:match("=> (%d+:%d+)$")
if duration then
total_seconds = total_seconds + parse_duration_to_seconds(duration)
count = count + 1
end
end
if count == 0 then
print("No valid clock lines found in selection.")
return
end
local total_duration_str = format_seconds_to_duration(total_seconds)
-- 3. Prepend Indent to the Result Row
local result_row_content = string.format("TOTAL_CLOCK_SUM: %s (from %d rows)", total_duration_str, count)
local result_row = indent .. result_row_content -- Add the captured indent here
-- Insert the result row below the selection.
vim.api.nvim_buf_set_lines(0, end_line, end_line, true, {result_row})
-- Move the cursor to the newly inserted line
vim.api.nvim_win_set_cursor(0, {end_line + 1, #indent + 1}) -- Move cursor past the indent
print(string.format("Clock sum calculated: %s", total_duration_str))
end
vim.api.nvim_create_user_command(
'ClockSum',
ClockSumSelectedLines,
{
range = true,
desc = 'Calculates total time from CLOCK rows and inserts the total below.'
}
)
vim.keymap.set(
'v', '<leader>cs',
":'<,'>ClockSum<CR>",
{noremap = true, silent = true, desc = 'Calculate Clock Sum for Selection'}
)
Additional context
No response
- Dominant language
- Lua
- Stars
- 3.9k
- Forks
- 192
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 18
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nvim-orgmode/orgmode
-
Difficulty 1/5 Under an hour Newbie friendliness 73/100
nvim-orgmode/orgmode#1193 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
nvim-orgmode/orgmode#1175 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
nvim-orgmode/orgmode#1174 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 92/100
nvim-orgmode/orgmode#1173 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 50/100
nvim-orgmode/orgmode#1172 ·
Maintainers usually reply within 1 day
All issues in nvim-orgmode/orgmode
Similar issues
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
eugenioenko/ttt#919 · 1 comment ·
Maintainers usually reply within 1 day
-
Profiler (Remotery) leaks a socket for every connection that fails the WebSocket handshakePossibly taken @rthery claimed this today. Opentriage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Mosquito: LOOP_ANT_LOCK reads the IFF detonator coverPossibly taken @cbass2404 claimed this today. OpenMosquito
Difficulty 1/5 Under an hour Newbie friendliness 88/100
DCS-Skunkworks/dcs-bios#1925 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 Under an hour Newbie friendliness 80/100
mason-org/mason.nvim#2117 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
mailcow/mailcow-dockerized#7518 ·
Maintainers usually reply within 1 day