From c817fb653d2015b353889447dba09846774299ef Mon Sep 17 00:00:00 2001 From: Emmanuel Touzery Date: Fri, 2 Aug 2024 18:44:33 +0200 Subject: [PATCH] feat: option to control log relative date display the user can now customize when to display using relative and absolute dates in the log. --- README.md | 1 + doc/diffview.txt | 5 +++++ lua/diffview/config.lua | 1 + lua/diffview/scene/views/file_history/render.lua | 4 +++- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9298e1f5..2ae3fbae 100644 --- a/README.md +++ b/README.md @@ -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", diff --git a/doc/diffview.txt b/doc/diffview.txt index 3a564c12..9c392b9f 100644 --- a/doc/diffview.txt +++ b/doc/diffview.txt @@ -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`, Default: `{}` diff --git a/lua/diffview/config.lua b/lua/diffview/config.lua index f1f6d0f1..4161962e 100644 --- a/lua/diffview/config.lua +++ b/lua/diffview/config.lua @@ -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", diff --git a/lua/diffview/scene/views/file_history/render.lua b/lua/diffview/scene/views/file_history/render.lua index 24b13970..bea3f88b 100644 --- a/lua/diffview/scene/views/file_history/render.lua +++ b/lua/diffview/scene/views/file_history/render.lua @@ -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 )