pool-stats/helpers/helpers.go
2025-05-27 22:56:44 +03:00

40 lines
819 B
Go

package helpers
import (
"fmt"
"strconv"
"strings"
"time"
)
func HumanDiff(diff float64) string {
units := []string{"", "K", "M", "G", "T"}
i := 0
for diff >= 1000 && i < len(units)-1 {
diff /= 1000
i++
}
return fmt.Sprintf("%.2f%s", diff, units[i])
}
func ParseCreateDate(createdate string) time.Time {
parts := strings.Split(createdate, ",")
if len(parts) == 2 {
sec, _ := strconv.ParseInt(parts[0], 10, 64)
nsec, _ := strconv.ParseInt(parts[1], 10, 64)
return time.Unix(sec, nsec)
}
return time.Time{}
}
func FormatCreateDate(createdate string) string {
parts := strings.Split(createdate, ",")
if len(parts) == 2 {
sec, _ := strconv.ParseInt(parts[0], 10, 64)
nsec, _ := strconv.ParseInt(parts[1], 10, 64)
t := time.Unix(sec, nsec)
return t.Format(time.DateTime)
}
return ""
}