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

time: relative_short(); fmt: handle $vweb.html()

This commit is contained in:
Alexander Medvednikov
2020-06-11 20:26:46 +02:00
parent 3bf9b28773
commit 72fdb09e46
4 changed files with 42 additions and 12 deletions

View File

@@ -189,6 +189,32 @@ fn since(t Time) int {
// relative returns a string representation of difference between time
// and current time.
pub fn (t Time) relative() string {
now := time.now()
secs := now.unix - t.unix
if secs <= 30 {
// right now or in the future
// TODO handle time in the future
return 'now'
}
if secs < 60 {
return '1m'
}
if secs < 3600 {
return '${secs/60} minutes ago'
}
if secs < 3600 * 24 {
return '${secs/3600} hours ago'
}
if secs < 3600 * 24 * 5 {
return '${secs/3600/24} days ago'
}
if secs > 3600 * 24 * 10000 {
return ''
}
return t.md()
}
pub fn (t Time) relative_short() string {
now := time.now()
secs := now.unix - t.unix
if secs <= 30 {