Files
zeekay 579f53c3cc chore: remove local replace directives and update dependencies
- Update github.com/luxfi/netrunner v1.15.3 → v1.15.4
- Update github.com/luxfi/node v1.22.77 → v1.22.80
- Remove local replace directive for netrunner
- Use published package versions for reproducible builds
2026-01-03 07:09:01 -08:00

43 lines
896 B
Go

// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package ux
import (
"fmt"
"strings"
"time"
)
// FormatDuration returns a user friendly string for a duration
func FormatDuration(d time.Duration) string {
var sb strings.Builder
y := d / (24 * 365 * time.Hour)
if y > 0 {
d -= y * 24 * 365 * time.Hour
_, _ = sb.WriteString(fmt.Sprintf("%d years ", y))
}
dd := d / (24 * time.Hour)
if dd > 0 {
d -= dd * 24 * time.Hour
_, _ = sb.WriteString(fmt.Sprintf("%d days ", dd))
}
h := d / time.Hour
if h > 0 {
d -= h * time.Hour
_, _ = sb.WriteString(fmt.Sprintf("%d hours ", h))
}
m := d / time.Minute
if m > 0 {
d -= m * time.Minute
_, _ = sb.WriteString(fmt.Sprintf("%d minutes ", m))
}
s := d / time.Second
if s > 0 {
_, _ = sb.WriteString(fmt.Sprintf("%d seconds ", s))
}
return sb.String()
}