2021-12-19 04:33:12 +00:00
|
|
|
package z
|
|
|
|
|
|
|
|
import (
|
2022-02-28 16:14:27 +00:00
|
|
|
"fmt"
|
|
|
|
"time"
|
2021-12-19 04:33:12 +00:00
|
|
|
|
2022-02-28 16:14:27 +00:00
|
|
|
"github.com/shopspring/decimal"
|
2021-12-19 04:33:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var fractional bool
|
|
|
|
|
|
|
|
func fmtDuration(dur time.Duration) (string) {
|
2022-02-28 16:14:27 +00:00
|
|
|
return fmtHours(decimal.NewFromFloat(dur.Hours()))
|
2021-12-19 04:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func fmtHours(hours decimal.Decimal) (string) {
|
2022-02-28 16:14:27 +00:00
|
|
|
if fractional {
|
|
|
|
return hours.StringFixed(2)
|
|
|
|
} else {
|
|
|
|
return fmt.Sprintf(
|
|
|
|
"%s:%02s",
|
|
|
|
hours.Floor(), // hours
|
2021-12-19 04:33:12 +00:00
|
|
|
hours.Sub(hours.Floor()).
|
2022-02-28 16:14:27 +00:00
|
|
|
Mul(decimal.NewFromFloat(.6)).
|
|
|
|
Mul(decimal.NewFromInt(100)).
|
|
|
|
Floor())
|
|
|
|
}
|
2021-12-19 04:33:12 +00:00
|
|
|
}
|