1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

time: fix relative()

This commit is contained in:
Alexander Medvednikov 2020-06-12 15:28:24 +02:00
parent 0838080fcd
commit 7750ce5f60

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 ''