summaryrefslogtreecommitdiffstats
path: root/pkg/gui/presentation
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/gui/presentation')
-rw-r--r--pkg/gui/presentation/commits.go11
-rw-r--r--pkg/gui/presentation/commits_test.go27
-rw-r--r--pkg/gui/presentation/reflog_commits.go26
3 files changed, 48 insertions, 16 deletions
diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go
index 6b83456b9..a2bba30ed 100644
--- a/pkg/gui/presentation/commits.go
+++ b/pkg/gui/presentation/commits.go
@@ -3,6 +3,7 @@ package presentation
import (
"fmt"
"strings"
+ "time"
"github.com/fsmiamoto/git-todo-parser/todo"
"github.com/jesseduffield/generics/set"
@@ -41,6 +42,8 @@ func GetCommitListDisplayStrings(
cherryPickedCommitShaSet *set.Set[string],
diffName string,
timeFormat string,
+ shortTimeFormat string,
+ now time.Time,
parseEmoji bool,
selectedCommitSha string,
startIdx int,
@@ -107,6 +110,8 @@ func GetCommitListDisplayStrings(
cherryPickedCommitShaSet,
diffName,
timeFormat,
+ shortTimeFormat,
+ now,
parseEmoji,
getGraphLine(unfilteredIdx),
fullDescription,
@@ -253,6 +258,8 @@ func displayCommit(
cherryPickedCommitShaSet *set.Set[string],
diffName string,
timeFormat string,
+ shortTimeFormat string,
+ now time.Time,
parseEmoji bool,
graphLine string,
fullDescription bool,
@@ -304,7 +311,9 @@ func displayCommit(
cols = append(cols, shaColor.Sprint(commit.ShortSha()))
cols = append(cols, bisectString)
if fullDescription {
- cols = append(cols, style.FgBlue.Sprint(utils.UnixToDate(commit.UnixTimestamp, timeFormat)))
+ cols = append(cols, style.FgBlue.Sprint(
+ utils.UnixToDateSmart(now, commit.UnixTimestamp, timeFormat, shortTimeFormat),
+ ))
}
cols = append(
cols,
diff --git a/pkg/gui/presentation/commits_test.go b/pkg/gui/presentation/commits_test.go
index a976d4809..31c6c813d 100644
--- a/pkg/gui/presentation/commits_test.go
+++ b/pkg/gui/presentation/commits_test.go
@@ -4,6 +4,7 @@ import (
"os"
"strings"
"testing"
+ "time"
"github.com/fsmiamoto/git-todo-parser/todo"
"github.com/gookit/color"
@@ -31,6 +32,8 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
cherryPickedCommitShaSet *set.Set[string]
diffName string
timeFormat string
+ shortTimeFormat string
+ now time.Time
parseEmoji bool
selectedCommitSha string
startIdx int
@@ -49,6 +52,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
+ now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: "",
},
{
@@ -62,6 +66,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
+ now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 commit1
sha2 commit2
@@ -81,6 +86,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
showGraph: true,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
+ now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 ⏣─╮ commit1
sha2 ◯ │ commit2
@@ -104,6 +110,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: true,
+ now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 pick commit1
sha2 pick commit2
@@ -127,6 +134,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: true,
+ now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha2 pick commit2
sha3 ◯ <-- YOU ARE HERE --- commit3
@@ -149,6 +157,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: true,
+ now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha4 ◯ commit4
sha5 ◯ commit5
@@ -169,6 +178,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: true,
+ now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 pick commit1
sha2 pick commit2
@@ -189,6 +199,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: true,
+ now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha5 ◯ commit5
`),
@@ -208,6 +219,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: true,
+ now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 pick commit1
sha2 pick commit2
@@ -226,6 +238,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
showYouAreHereLabel: false,
+ now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 pick commit1
sha2 ◯ commit2
@@ -235,19 +248,21 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
{
testName: "custom time format",
commits: []*models.Commit{
- {Name: "commit1", Sha: "sha1", UnixTimestamp: 1652443200, AuthorName: "Jesse Duffield"},
- {Name: "commit2", Sha: "sha2", UnixTimestamp: 1652529600, AuthorName: "Jesse Duffield"},
+ {Name: "commit1", Sha: "sha1", UnixTimestamp: 1577844184, AuthorName: "Jesse Duffield"},
+ {Name: "commit2", Sha: "sha2", UnixTimestamp: 1576844184, AuthorName: "Jesse Duffield"},
},
fullDescription: true,
- timeFormat: "2006-01-02 15:04:05",
+ timeFormat: "2006-01-02",
+ shortTimeFormat: "3:04PM",
startIdx: 0,
length: 2,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
+ now: time.Date(2020, 1, 1, 5, 3, 4, 0, time.UTC),
expected: formatExpected(`
- sha1 2022-05-13 12:00:00 Jesse Duffield commit1
- sha2 2022-05-14 12:00:00 Jesse Duffield commit2
+ sha1 2:03AM Jesse Duffield commit1
+ sha2 2019-12-20 Jesse Duffield commit2
`),
},
}
@@ -274,6 +289,8 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
s.cherryPickedCommitShaSet,
s.diffName,
s.timeFormat,
+ s.shortTimeFormat,
+ s.now,
s.parseEmoji,
s.selectedCommitSha,
s.startIdx,
diff --git a/pkg/gui/presentation/reflog_commits.go b/pkg/gui/presentation/reflog_commits.go
index 5a49f0374..65e0a27bb 100644
--- a/pkg/gui/presentation/reflog_commits.go
+++ b/pkg/gui/presentation/reflog_commits.go
@@ -1,6 +1,8 @@
package presentation
import (
+ "time"
+
"github.com/jesseduffield/generics/set"
"github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/commands/models"
@@ -10,7 +12,7 @@ import (
"github.com/kyokomi/emoji/v2"
)
-func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaSet *set.Set[string], diffName string, timeFormat string, parseEmoji bool) [][]string {
+func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaSet *set.Set[string], diffName string, now time.Time, timeFormat string, shortTimeFormat string, parseEmoji bool) [][]string {
var displayFunc func(*models.Commit, reflogCommitDisplayAttributes) []string
if fullDescription {
displayFunc = getFullDescriptionDisplayStringsForReflogCommit
@@ -23,10 +25,12 @@ func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription
cherryPicked := cherryPickedCommitShaSet.Includes(commit.Sha)
return displayFunc(commit,
reflogCommitDisplayAttributes{
- cherryPicked: cherryPicked,
- diffed: diffed,
- parseEmoji: parseEmoji,
- timeFormat: timeFormat,
+ cherryPicked: cherryPicked,
+ diffed: diffed,
+ parseEmoji: parseEmoji,
+ timeFormat: timeFormat,
+ shortTimeFormat: shortTimeFormat,
+ now: now,
})
})
}
@@ -45,10 +49,12 @@ func reflogShaColor(cherryPicked, diffed bool) style.TextStyle {
}
type reflogCommitDisplayAttributes struct {
- cherryPicked bool
- diffed bool
- parseEmoji bool
- timeFormat string
+ cherryPicked bool
+ diffed bool
+ parseEmoji bool
+ timeFormat string
+ shortTimeFormat string
+ now time.Time
}
func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, attrs reflogCommitDisplayAttributes) []string {
@@ -59,7 +65,7 @@ func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, attrs ref
return []string{
reflogShaColor(attrs.cherryPicked, attrs.diffed).Sprint(c.ShortSha()),
- style.FgMagenta.Sprint(utils.UnixToDate(c.UnixTimestamp, attrs.timeFormat)),
+ style.FgMagenta.Sprint(utils.UnixToDateSmart(attrs.now, c.UnixTimestamp, attrs.timeFormat, attrs.shortTimeFormat)),
theme.DefaultTextColor.Sprint(name),
}
}