add documentation

This commit is contained in:
2021-05-09 17:25:23 -04:00
parent 1ee89cad34
commit 573de70682
5 changed files with 45 additions and 17 deletions

View File

@@ -5,17 +5,20 @@ import (
"time"
)
// Info defines a version and a commit time for that version
type Info struct {
Version string // version string
Time time.Time // commit time
}
// Pair is a set of versions for a dependency (current and newest possible)
type Pair struct {
Name string
Latest Info
Current Info
}
// Calc returns the summed time distance (as a time.Duration) between a set of Pairs of modules.
// 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 {
@@ -26,6 +29,7 @@ func Calc(p ...Pair) time.Duration {
return sum
}
// DecimalYear conversts a time.Duration (which is in nsec) to a two-decimal-place count of years.
func DecimalYear(d time.Duration) string {
return fmt.Sprintf("%.2f", float64(d.Truncate(time.Hour)/time.Hour)/float64(8760))
}