summaryrefslogtreecommitdiff
path: root/humanFormat.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-12 04:29:32 -0500
committerJeff Carr <[email protected]>2025-10-12 04:29:32 -0500
commit2cbb97212954cb20c535dd70b32c86bbf8cb0f09 (patch)
tree30a218d0044e6bf0a851693dd240e0b18f710153 /humanFormat.go
parenta4918390cb47f409476fe4135009ffe4d5255375 (diff)
config has no go deps anymore
Diffstat (limited to 'humanFormat.go')
-rw-r--r--humanFormat.go113
1 files changed, 0 insertions, 113 deletions
diff --git a/humanFormat.go b/humanFormat.go
deleted file mode 100644
index e501490..0000000
--- a/humanFormat.go
+++ /dev/null
@@ -1,113 +0,0 @@
-package config
-
-import (
- "fmt"
- "time"
-)
-
-/*
- etimef := func(e *forgepb.Set) string {
- etime := e.Etime.AsTime()
- s := etime.Format("2006/01/02 15:04")
- if strings.HasPrefix(s, "1970/") {
- // just show a blank if it's not set
- return ""
- }
- return s
- }
- t.AddStringFunc("etime", etimef)
-*/
-
-/*
- ctimef := func(p *forgepb.Set) string {
- ctime := p.Ctime.AsTime()
- return ctime.Format("2006/01/02 15:04")
- }
-}
-*/
-
-// This isn't for the marketing department
-// so this isn't going to use 'MiB' and 'GiB'
-func HumanFormatBytes(b int) string {
- if b < 2000 {
- return fmt.Sprintf("%d B", b)
- }
-
- kb := int(b / 1024)
- if kb < 2000 {
- return fmt.Sprintf("%d KB", kb)
- }
-
- mb := int(b / (1024 * 1024))
- if mb < 2000 {
- return fmt.Sprintf("%d MB", mb)
- }
-
- gb := int(b / (1024 * 1024 * 1024))
- if gb < 2000 {
- return fmt.Sprintf("%d GB", gb)
- }
-
- tb := int(b / (1024 * 1024 * 1024 * 1024))
- return fmt.Sprintf("%d TB", tb)
-}
-
-func FormatDuration(d time.Duration) string {
- result := ""
-
- // check if it's more than a year
- years := int(d.Hours()) / (24 * 365)
- if years > 0 {
- result += fmt.Sprintf("%dy", years)
- return result
- }
-
- // check if it's more than a day
- days := int(d.Hours()) / 24
- if days > 0 {
- result += fmt.Sprintf("%dd", days)
- return result
- }
-
- // check if it's more than an hour
- hours := int(d.Hours()) % 24
- if hours > 0 {
- result += fmt.Sprintf("%dh", hours)
- return result
- }
-
- // check if it's more than a minute
- minutes := int(d.Minutes()) % 60
- if minutes > 0 {
- result += fmt.Sprintf("%dm", minutes)
- return result
- }
-
- // check if it's more than a second
- seconds := int(d.Seconds()) % 60
- if seconds > 0 {
- result += fmt.Sprintf("%ds", seconds)
- return result
- }
-
- // report in milliseconds
- ms := int(d.Milliseconds())
- if ms > 100 {
- // todo: print .3s, etc ?
- }
- if ms > 0 {
- result += fmt.Sprintf("%dms", ms)
- return result
- }
-
- // report in milliseconds
- mc := int(d.Microseconds())
- if mc > 0 {
- result += fmt.Sprintf("%dmc", mc)
- return result
- }
-
- ns := int(d.Nanoseconds())
- result += fmt.Sprintf("%dns", ns)
- return result
-}