all repos — honk @ 796a7b6386b06fa60edc826e08c98c3073654e39

my fork of honk

prettify dates
Anirudh Oppiliappan x@icyphox.sh
Wed, 09 Nov 2022 11:29:26 +0530
commit

796a7b6386b06fa60edc826e08c98c3073654e39

parent

2daaeb1ea62fbbe3618c045de9cddb9b598b3599

6 files changed, 33 insertions(+), 2 deletions(-)

jump to
M fun.gofun.go

@@ -28,6 +28,7 @@ "regexp"

"strings" "time" + "github.com/dustin/go-humanize" "golang.org/x/net/html" "humungus.tedunangst.com/r/webs/cache" "humungus.tedunangst.com/r/webs/htfilter"

@@ -61,10 +62,36 @@ relingo[l] = v

} } +func prettifydate(d time.Time) string { + var customMags = []humanize.RelTimeMagnitude{ + {time.Second, "now", time.Second}, + {2 * time.Second, "1s %s", 1}, + {time.Minute, "%ds %s", time.Second}, + {2 * time.Minute, "1m %s", 1}, + {time.Hour, "%dm %s", time.Minute}, + {2 * time.Hour, "1h %s", 1}, + {humanize.Day, "%dh %s", time.Hour}, + {2 * humanize.Day, "1d %s", 1}, + {humanize.Week, "%dd %s", humanize.Day}, + {2 * humanize.Week, "1w %s", 1}, + {humanize.Month, "%dw %s", humanize.Week}, + } + + since := time.Since(d) + // More than a month, return the actual date. + if since.Hours() > 730 { + return d.Format("02 Jan 2006 15:04") + } + + return humanize.CustomRelTime(d, time.Now(), "", "from now", customMags) +} + func reverbolate(userid int64, honks []*Honk) { var user *WhatAbout somenumberedusers.Get(userid, &user) for _, h := range honks { + // idk where else to put this + h.DatePretty = prettifydate(h.Date) h.What += "ed" if h.What == "tonked" { h.What = "honked back"
M go.modgo.mod

@@ -4,6 +4,7 @@ go 1.16

require ( github.com/andybalholm/cascadia v1.3.1 + github.com/dustin/go-humanize v1.0.0 github.com/gorilla/mux v1.8.0 github.com/mattn/go-runewidth v0.0.13 golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
M go.sumgo.sum

@@ -1,5 +1,7 @@

github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c= github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA= +github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
M honk.gohonk.go

@@ -83,6 +83,7 @@ Oondle string

XID string RID string Date time.Time + DatePretty string URL string Noise string Precis string
M views/honk.htmlviews/honk.html

@@ -27,7 +27,7 @@ <a class="honkerlink" href="/h?xid={{ .Honker }}" data-xid="{{ .Honker }}">{{ .Username }}</a>

{{ else }} <a href="{{ .Honker }}" rel=noreferrer>{{ .Username }}</a> {{ end }} -<span class="clip"><a href="{{ .URL }}" rel=noreferrer>{{ .What }}</a> <span id="honkdate">{{ .Date.Local.Format "02 Jan 2006 15:04" }}</span> </span> +<span class="clip"><a href="{{ .URL }}" rel=noreferrer>{{ .What }}</a> <span style="float: right;" id="honkdate">{{ .DatePretty }}</span> </span> {{ if .Oonker }} <br> <span style="margin-left: 1em;" class="clip">
M web.goweb.go

@@ -2124,7 +2124,7 @@ if uinfo == nil {

a = avatateautogen(r) goto nope } - j, err := GetJunkFast(uinfo.UserID, n) + j, err := GetJunkFast(uinfo.UserID, n) if err != nil { dlog.Println("avatating: getting junk:", err) a = avatateautogen(r)