mirror of
https://github.com/lone-cloud/prism
synced 2026-06-03 19:54:44 -07:00
43 lines
914 B
Go
43 lines
914 B
Go
package util
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func FormatPhoneNumber(number string) string {
|
|
cleaned := strings.ReplaceAll(number, " ", "")
|
|
cleaned = strings.ReplaceAll(cleaned, "-", "")
|
|
cleaned = strings.ReplaceAll(cleaned, "(", "")
|
|
cleaned = strings.ReplaceAll(cleaned, ")", "")
|
|
|
|
if !strings.HasPrefix(cleaned, "+") {
|
|
cleaned = "+" + cleaned
|
|
}
|
|
|
|
return cleaned
|
|
}
|
|
|
|
func FormatUptime(d time.Duration) string {
|
|
days := int(d.Hours()) / 24
|
|
hours := int(d.Hours()) % 24
|
|
minutes := int(d.Minutes()) % 60
|
|
seconds := int(d.Seconds()) % 60
|
|
|
|
parts := []string{}
|
|
if days > 0 {
|
|
parts = append(parts, fmt.Sprintf("%dd", days))
|
|
}
|
|
if hours > 0 {
|
|
parts = append(parts, fmt.Sprintf("%dh", hours))
|
|
}
|
|
if minutes > 0 {
|
|
parts = append(parts, fmt.Sprintf("%dm", minutes))
|
|
}
|
|
if seconds > 0 || len(parts) == 0 {
|
|
parts = append(parts, fmt.Sprintf("%ds", seconds))
|
|
}
|
|
|
|
return strings.Join(parts, " ")
|
|
}
|