time: fix relative()

pull/5364/head
Alexander Medvednikov 2020-06-12 15:28:24 +02:00
parent 0838080fcd
commit 7750ce5f60
1 changed files with 15 additions and 3 deletions

View File

@ -200,13 +200,25 @@ pub fn (t Time) relative() string {
return '1m' return '1m'
} }
if secs < 3600 { if secs < 3600 {
return '${secs/60} minutes ago' m := secs/60
if m == 1 {
return '1 minute ago'
}
return '$m minutes ago'
} }
if secs < 3600 * 24 { if secs < 3600 * 24 {
return '${secs/3600} hours ago' h := secs/3600
if h == 1 {
return '1 hour ago'
}
return '$h hours ago'
} }
if secs < 3600 * 24 * 5 { if secs < 3600 * 24 * 5 {
return '${secs/3600/24} days ago' d:=secs/3600/24
if d == 1 {
return '1 day ago'
}
return '$d days ago'
} }
if secs > 3600 * 24 * 10000 { if secs > 3600 * 24 * 10000 {
return '' return ''