Skip to content

feat: option to control log relative date display #525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ require("diffview").setup({
single_file = {},
multi_file = {},
},
relative_date_cutoff_seconds = 60 * 60 * 24 * 30 * 3, -- 3 months
},
win_config = { -- See |diffview-config-win_config|
position = "bottom",
Expand Down
5 changes: 5 additions & 0 deletions doc/diffview.txt
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,11 @@ log_options *diffview-config-log_options*
{multi_file} (`LogOptions`)
See |diffview.git.LogOptions|.

{relative_date_cutoff_seconds} (integer)
Dates newer than this number of seconds ago will be displayed
as relative (eg "2 hours ago"), while older ones will be
displayed as full ISO dates (Fri Aug 2, ...).

default_args *diffview-config-default_args*
Type: `table<string, string[]>`, Default: `{}`

Expand Down
1 change: 1 addition & 0 deletions lua/diffview/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ M.defaults = {
single_file = {},
multi_file = {},
},
relative_date_cutoff_seconds = 60 * 60 * 24 * 30 * 3 -- 3 months
},
win_config = {
position = "bottom",
Expand Down
4 changes: 3 additions & 1 deletion lua/diffview/scene/views/file_history/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ local function render_entries(panel, parent, entries, updating)

if entry.commit then
-- 3 months
local relative_date_cutoff_seconds =
config.get_config().file_history_panel.log_options.relative_date_cutoff_seconds or (60 * 60 * 24 * 30 * 3)
local date = (
os.difftime(os.time(), entry.commit.time) > 60 * 60 * 24 * 30 * 3
os.difftime(os.time(), entry.commit.time) > relative_date_cutoff_seconds
and entry.commit.iso_date
or entry.commit.rel_date
)
Expand Down