feat(object): render author/committer/tagger dates in human form

This commit is contained in:
2026-05-26 23:47:13 +02:00
parent 22309fe8fd
commit 182e507dc7
5 changed files with 85 additions and 19 deletions
+1 -16
View File
@@ -56,21 +56,6 @@ function M.state(buf)
return states[buf]
end
---@param ts integer
---@param tz string
---@return string
local function format_author_time(ts, tz)
local sign, hh, mm = tz:match("^([+-])(%d%d)(%d%d)$")
---@type number
local offset = 0
if sign then
local h = tonumber(hh) or 0
local m = tonumber(mm) or 0
offset = (h * 3600 + m * 60) * (sign == "-" and -1 or 1)
end
return os.date("!%Y-%m-%d %T ", ts + offset) .. tz
end
---@param stdout string
---@return ow.Git.Blame.Result
local function parse_porcelain(stdout)
@@ -534,7 +519,7 @@ local function open_popup(state, lnum, watch_buf)
head = { "Not Committed Yet" }
else
local short = sha:sub(1, 8)
local date = format_author_time(commit.author_time, commit.author_tz)
local date = util.format_git_time(commit.author_time, commit.author_tz)
sha_len = #short
date_col = sha_len + 2 + #commit.author + 2
head = {
+17
View File
@@ -120,6 +120,23 @@ function M.split_lines(content)
return lines
end
---@param ts integer
---@param tz string
---@return string
function M.format_git_time(ts, tz)
local sign, hh, mm = tz:match("^([+-])(%d%d)(%d%d)$")
local offset = 0
if sign then
local h = tonumber(hh) or 0
local m = tonumber(mm) or 0
offset = math.floor(h * 3600 + m * 60)
if sign == "-" then
offset = -offset
end
end
return os.date("!%a %b %e %T %Y ", ts + offset) .. tz
end
---@param buf integer
---@param ns integer
---@param lines string[]
+26 -1
View File
@@ -159,6 +159,29 @@ function M.buf_for(r, rev)
return buf
end
---@param lines string[]
local function format_header_dates(lines)
for i, line in ipairs(lines) do
if line == "" then
return
end
local prefix, ts, tz = line:match("^(author .-) (%d+) ([+-]%d%d%d%d)$")
if not prefix then
prefix, ts, tz = line:match("^(committer .-) (%d+) ([+-]%d%d%d%d)$")
end
if not prefix then
prefix, ts, tz = line:match("^(tagger .-) (%d+) ([+-]%d%d%d%d)$")
end
if prefix then
local n = math.floor(assert(tonumber(ts)))
lines[i] = ("%s %s"):format(
prefix,
util.format_git_time(n, tz --[[@as string]])
)
end
end
end
---@param buf integer
---@param r ow.Git.Repo
---@param rev ow.Git.Revision
@@ -189,7 +212,9 @@ local function populate(buf, r, rev, state, rev_sha)
end
end
util.set_buf_lines(buf, 0, -1, util.split_lines(stdout))
local lines = util.split_lines(stdout)
format_header_dates(lines)
util.set_buf_lines(buf, 0, -1, lines)
state.sha = rev_sha
return true
end