32 lines
654 B
Go
32 lines
654 B
Go
package libyear
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type Info struct {
|
|
Version string // version string
|
|
Time time.Time // commit time
|
|
}
|
|
|
|
type Pair struct {
|
|
Name string
|
|
Latest Info
|
|
Current Info
|
|
}
|
|
|
|
// TODO: sum can only represent ~290 years before overflowing, but we don't actually need nanosecond precision!
|
|
// Probably worth switching to hour-based summing here.
|
|
func Calc(p ...Pair) time.Duration {
|
|
sum := time.Duration(0)
|
|
for i := range p {
|
|
sum = sum + p[i].Latest.Time.Sub(p[i].Current.Time)
|
|
}
|
|
return sum
|
|
}
|
|
|
|
func DecimalYear(d time.Duration) string {
|
|
return fmt.Sprintf("%.2f", float64(d.Truncate(time.Hour)/time.Hour)/float64(8760))
|
|
}
|