From ce5c5845e761ab087616ed8487f3ed98a63e572b Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Sun, 22 Nov 2020 17:18:17 +0300 Subject: [PATCH] use year instead of hh:mm for old files in info Related #507 --- ui.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ui.go b/ui.go index 0bb189c..8cc637b 100644 --- a/ui.go +++ b/ui.go @@ -262,6 +262,15 @@ func (win *win) printReg(screen tcell.Screen, reg *reg) { } } +var gThisYear = time.Now().Year() + +func infotimefmt(t time.Time) string { + if t.Year() == gThisYear { + return t.Format("Jan _2 15:04") + } + return t.Format("Jan _2 2006") +} + func fileInfo(f *file, d *dir) string { var info string @@ -300,11 +309,11 @@ func fileInfo(f *file, d *dir) string { info = fmt.Sprintf("%s 999+", info) } case "time": - info = fmt.Sprintf("%s %12s", info, f.ModTime().Format("Jan _2 15:04")) + info = fmt.Sprintf("%s %12s", info, infotimefmt(f.ModTime())) case "atime": - info = fmt.Sprintf("%s %12s", info, f.accessTime.Format("Jan _2 15:04")) + info = fmt.Sprintf("%s %12s", info, infotimefmt(f.accessTime)) case "ctime": - info = fmt.Sprintf("%s %12s", info, f.changeTime.Format("Jan _2 15:04")) + info = fmt.Sprintf("%s %12s", info, infotimefmt(f.changeTime)) default: log.Printf("unknown info type: %s", s) }