Skip to content

Commit 0875d9c

Browse files
committed
feat(config): add date_format option for file history panel (sindrets#525)
Control how dates are displayed in the file history panel: - "auto" (default): relative for recent commits (< 3 months), ISO for old - "relative": always show relative dates (e.g., "2 days ago") - "iso": always show ISO dates
1 parent 0fb4d16 commit 0875d9c

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

doc/diffview_defaults.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ DEFAULT CONFIG *diffview.defaults*
8484
height = 16,
8585
win_opts = {},
8686
},
87+
date_format = "auto", -- Date format: "auto" | "relative" | "iso"
8788
},
8889
commit_log_panel = {
8990
win_config = {}, -- See |diffview-config-win_config|

lua/diffview/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ M.defaults = {
116116
win_opts = {}
117117
},
118118
commit_subject_max_length = 72, -- Max length for commit subject display.
119+
date_format = "auto", -- Date format: "auto" (relative for recent, ISO for old), "relative", or "iso".
119120
},
120121
commit_log_panel = {
121122
win_config = {

lua/diffview/scene/views/file_history/render.lua

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,20 @@ local function render_entries(panel, parent, entries, updating)
157157
)
158158

159159
if entry.commit then
160-
-- 3 months
161-
local date = (
162-
os.difftime(os.time(), entry.commit.time) > 60 * 60 * 24 * 30 * 3
163-
and entry.commit.iso_date
164-
or entry.commit.rel_date
165-
)
160+
local date_format = config.get_config().file_history_panel.date_format
161+
local date
162+
if date_format == "relative" then
163+
date = entry.commit.rel_date
164+
elseif date_format == "iso" then
165+
date = entry.commit.iso_date
166+
else
167+
-- "auto": show relative for recent commits (< 3 months), ISO for older.
168+
date = (
169+
os.difftime(os.time(), entry.commit.time) > 60 * 60 * 24 * 30 * 3
170+
and entry.commit.iso_date
171+
or entry.commit.rel_date
172+
)
173+
end
166174
comp:add_text(" " .. entry.commit.author .. ", " .. date, "DiffviewFilePanelPath")
167175
end
168176

0 commit comments

Comments
 (0)