Files
socket-comm/pkg/middleware/encrypt/util.go
2025-04-26 14:36:25 +05:30

20 lines
424 B
Go

package encrypt
import (
"fmt"
"time"
)
// FormatDuration formats a duration in a human-readable way
func FormatDuration(d time.Duration) string {
if d < time.Second {
return fmt.Sprintf("%d ms", d.Milliseconds())
} else if d < time.Minute {
return fmt.Sprintf("%.1f s", d.Seconds())
} else if d < time.Hour {
return fmt.Sprintf("%.1f min", d.Minutes())
} else {
return fmt.Sprintf("%.1f h", d.Hours())
}
}