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:
parent
c01c94c64c
commit
43c9a92748
6 changed files with 329 additions and 36 deletions
util
33
util/util.go
33
util/util.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue