minor improvement

pull/137/head
Simon Let 6 years ago
parent 7c68d1da13
commit f3d3180f4f
  1. 48
      cmd/cli/item.go

@ -64,47 +64,47 @@ func formatDatetime(tm time.Time) string {
tmSince := time.Since(tm) tmSince := time.Since(tm)
hrs := tmSince.Hours() hrs := tmSince.Hours()
yrs := int(hrs / (365 * 24)) yrs := int(hrs / (365 * 24))
if yrs > 1 { if yrs > 0 {
if yrs == 1 {
return "1 year ago"
}
return strconv.Itoa(yrs) + " years ago" return strconv.Itoa(yrs) + " years ago"
} }
if yrs == 1 {
return "1 year ago"
}
months := int(hrs / (30 * 24)) months := int(hrs / (30 * 24))
if months > 1 { if months > 0 {
if months == 1 {
return "1 month ago"
}
return strconv.Itoa(months) + " months ago" return strconv.Itoa(months) + " months ago"
} }
if months == 1 {
return "1 month ago"
}
days := int(hrs / 24) days := int(hrs / 24)
if days > 1 { if days > 0 {
if days == 1 {
return "1 day ago"
}
return strconv.Itoa(days) + " days ago" return strconv.Itoa(days) + " days ago"
} }
if days == 1 {
return "1 day ago"
}
hrsInt := int(hrs) hrsInt := int(hrs)
if hrsInt > 1 { if hrsInt > 0 {
if hrsInt == 1 {
return "1 hour ago"
}
return strconv.Itoa(hrsInt) + " hours ago" return strconv.Itoa(hrsInt) + " hours ago"
} }
if hrsInt == 1 {
return "1 hour ago"
}
mins := int(hrs * 60) mins := int(hrs * 60)
if mins > 1 { if mins > 0 {
if mins == 1 {
return "1 min ago"
}
return strconv.Itoa(mins) + " mins ago" return strconv.Itoa(mins) + " mins ago"
} }
if mins == 1 {
return "1 min ago"
}
secs := int(hrs * 60 * 60) secs := int(hrs * 60 * 60)
if secs > 1 { if secs > 0 {
if secs == 1 {
return "1 sec ago"
}
return strconv.Itoa(secs) + " secs ago" return strconv.Itoa(secs) + " secs ago"
} }
if secs == 1 {
return "1 sec ago"
}
return "now" return "now"
} }

Loading…
Cancel
Save