From 88ce0c3c2d15606ecef408d27d21181d4bcc577d Mon Sep 17 00:00:00 2001 From: hpo3 Date: Wed, 16 Jun 2021 09:10:24 +0800 Subject: [PATCH] Bugfix: listing result modify time error when file older than one year File older than one year time error --- list_formatter.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/list_formatter.go b/list_formatter.go index 951eedf..db7af29 100644 --- a/list_formatter.go +++ b/list_formatter.go @@ -9,6 +9,7 @@ import ( "fmt" "strconv" "strings" + "time" ) type listFormatter []FileInfo @@ -31,7 +32,11 @@ func (formatter listFormatter) Detailed() []byte { fmt.Fprint(&buf, file.Mode().String()) fmt.Fprintf(&buf, " 1 %s %s ", file.Owner(), file.Group()) fmt.Fprint(&buf, lpad(strconv.FormatInt(file.Size(), 10), 12)) - fmt.Fprint(&buf, file.ModTime().Format(" Jan _2 15:04 ")) + if file.ModTime().Before(time.Now().AddDate(-1, 0, 0)) { + fmt.Fprint(&buf, file.ModTime().Format(" Jan _2 2006 ")) + } else{ + fmt.Fprint(&buf, file.ModTime().Format(" Jan _2 15:04 ")) + } fmt.Fprintf(&buf, "%s\r\n", file.Name()) } return buf.Bytes() -- 2.40.1