···49 "sub": func(a, b int) int {
50 return a - b
51 },
00000000000000000000052 "cond": func(cond interface{}, a, b string) string {
53 if cond == nil {
54 return b
···104 {humanize.LongTime, "%dy %s", humanize.Year},
105 {math.MaxInt64, "a long while %s", 1},
106 })
00000000000000000000000000107 },
108 "byteFmt": humanize.Bytes,
109 "length": func(slice any) int {
···49 "sub": func(a, b int) int {
50 return a - b
51 },
52+ "f64": func(a int) float64 {
53+ return float64(a)
54+ },
55+ "addf64": func(a, b float64) float64 {
56+ return a + b
57+ },
58+ "subf64": func(a, b float64) float64 {
59+ return a - b
60+ },
61+ "mulf64": func(a, b float64) float64 {
62+ return a * b
63+ },
64+ "divf64": func(a, b float64) float64 {
65+ if b == 0 {
66+ return 0
67+ }
68+ return a / b
69+ },
70+ "negf64": func(a float64) float64 {
71+ return -a
72+ },
73 "cond": func(cond interface{}, a, b string) string {
74 if cond == nil {
75 return b
···125 {humanize.LongTime, "%dy %s", humanize.Year},
126 {math.MaxInt64, "a long while %s", 1},
127 })
128+ },
129+ "durationFmt": func(duration time.Duration) string {
130+ days := int64(duration.Hours() / 24)
131+ hours := int64(math.Mod(duration.Hours(), 24))
132+ minutes := int64(math.Mod(duration.Minutes(), 60))
133+ seconds := int64(math.Mod(duration.Seconds(), 60))
134+135+ chunks := []struct {
136+ name string
137+ amount int64
138+ }{
139+ {"d", days},
140+ {"hr", hours},
141+ {"min", minutes},
142+ {"s", seconds},
143+ }
144+145+ parts := []string{}
146+147+ for _, chunk := range chunks {
148+ if chunk.amount != 0 {
149+ parts = append(parts, fmt.Sprintf("%d%s", chunk.amount, chunk.name))
150+ }
151+ }
152+153+ return strings.Join(parts, " ")
154 },
155 "byteFmt": humanize.Bytes,
156 "length": func(slice any) int {