fix(format): move time format to text

This commit is contained in:
jguer 2020-06-26 09:15:36 +02:00
parent d0450179f9
commit acf95aed5b
No known key found for this signature in database
GPG key ID: 6D6CC9BEA8556B35
2 changed files with 20 additions and 17 deletions

15
pkg/text/time.go Normal file
View file

@ -0,0 +1,15 @@
package text
import "time"
// Formats a unix timestamp to ISO 8601 date (yyyy-mm-dd)
func FormatTime(i int) string {
t := time.Unix(int64(i), 0)
return t.Format("2006-01-02")
}
// Formats a unix timestamp to ISO 8601 date (Mon 02 Jan 2006 03:04:05 PM MST)
func FormatTimeQuery(i int) string {
t := time.Unix(int64(i), 0)
return t.Format("Mon 02 Jan 2006 03:04:05 PM MST")
}

View file

@ -79,7 +79,7 @@ func (q aurQuery) printSearch(start int) {
}
if q[i].OutOfDate != 0 {
toprint += bold(red(gotext.Get("(Out-of-date: %s)", formatTime(q[i].OutOfDate)))) + " "
toprint += bold(red(gotext.Get("(Out-of-date: %s)", text.FormatTime(q[i].OutOfDate)))) + " "
}
if pkg := localDB.Pkg(q[i].Name); pkg != nil {
@ -287,11 +287,11 @@ func PrintInfo(a *rpc.Pkg) {
text.PrintInfoValue(gotext.Get("Maintainer"), a.Maintainer)
text.PrintInfoValue(gotext.Get("Votes"), fmt.Sprintf("%d", a.NumVotes))
text.PrintInfoValue(gotext.Get("Popularity"), fmt.Sprintf("%f", a.Popularity))
text.PrintInfoValue(gotext.Get("First Submitted"), formatTimeQuery(a.FirstSubmitted))
text.PrintInfoValue(gotext.Get("Last Modified"), formatTimeQuery(a.LastModified))
text.PrintInfoValue(gotext.Get("First Submitted"), text.FormatTimeQuery(a.FirstSubmitted))
text.PrintInfoValue(gotext.Get("Last Modified"), text.FormatTimeQuery(a.LastModified))
if a.OutOfDate != 0 {
text.PrintInfoValue(gotext.Get("Out-of-date"), formatTimeQuery(a.OutOfDate))
text.PrintInfoValue(gotext.Get("Out-of-date"), text.FormatTimeQuery(a.OutOfDate))
} else {
text.PrintInfoValue(gotext.Get("Out-of-date"), "No")
}
@ -456,7 +456,7 @@ func (item *item) print(buildTime time.Time) {
if err != nil {
fmt.Fprintln(os.Stderr, err)
} else {
fd = formatTime(int(date.Unix()))
fd = text.FormatTime(int(date.Unix()))
if _, double, _ := cmdArgs.getArg("news", "w"); !double && !buildTime.IsZero() {
if buildTime.After(date) {
return
@ -523,18 +523,6 @@ func printNewsFeed() error {
return nil
}
// Formats a unix timestamp to ISO 8601 date (yyyy-mm-dd)
func formatTime(i int) string {
t := time.Unix(int64(i), 0)
return t.Format("2006-01-02")
}
// Formats a unix timestamp to ISO 8601 date (Mon 02 Jan 2006 03:04:05 PM MST)
func formatTimeQuery(i int) string {
t := time.Unix(int64(i), 0)
return t.Format("Mon 02 Jan 2006 03:04:05 PM MST")
}
const (
redCode = "\x1b[31m"
greenCode = "\x1b[32m"