orangesite/hn/misc.go
sneak 0d9ed8874f
All checks were successful
continuous-integration/drone/push Build is passing
made to suck less, including:
* `make` works again, exporting correct database file path for local dev
* better formatting of durations
* refactored duration math to misc functions
* now tracks and displays score
* displays short-lifetime fp wipeouts in red
2020-03-25 07:50:10 -07:00

21 lines
428 B
Go

package hn
import (
"math"
"time"
"github.com/hako/durafmt"
)
func timeDiffHuman(first time.Time, second time.Time) string {
if first.Before(second) {
return durafmt.ParseShort(second.Sub(first)).String()
} else {
return durafmt.ParseShort(first.Sub(second)).String()
}
}
func timeDiffAbsSeconds(first time.Time, second time.Time) uint {
return uint(math.Abs(first.Sub(second).Truncate(time.Second).Seconds()))
}