1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-06-09 22:44:36 +02:00
This commit is contained in:
Philipp Heckel 2022-06-21 11:18:35 -04:00
parent 0080ea5a20
commit a160da3ad9
4 changed files with 100 additions and 83 deletions

View file

@ -121,38 +121,6 @@ func ValidRandomString(s string, length int) bool {
return true
}
// 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
}
// ParsePriority parses a priority string into its equivalent integer value
func ParsePriority(priority string) (int, error) {
switch strings.TrimSpace(strings.ToLower(priority)) {