1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-05-27 17:05:36 +02:00

Detail page in web UI

This commit is contained in:
Philipp Heckel 2021-11-08 09:24:34 -05:00
parent c01c94c64c
commit 43c9a92748
6 changed files with 329 additions and 36 deletions

View file

@ -1,6 +1,7 @@
package util
import (
"fmt"
"math/rand"
"os"
"time"
@ -27,3 +28,35 @@ func RandomString(length int) string {
}
return string(b)
}
// DurationToHuman converts a duration to a human readable format
func DurationToHuman(d time.Duration) (str string) {
if d == 0 {
return "0"
}
d = d.Round(time.Second)
days := d / time.Hour / 24
if days > 0 {
str += fmt.Sprintf("%dd", days)
}
d -= days * time.Hour * 24
hours := d / time.Hour
if hours > 0 {
str += fmt.Sprintf("%dh", hours)
}
d -= hours * time.Hour
minutes := d / time.Minute
if minutes > 0 {
str += fmt.Sprintf("%dm", minutes)
}
d -= minutes * time.Minute
seconds := d / time.Second
if seconds > 0 {
str += fmt.Sprintf("%ds", seconds)
}
return
}