move contribution from ledger to ana

This commit is contained in:
Bel LaPointe
2023-10-26 10:17:54 -06:00
parent 2bc17fccf2
commit a516cb84ad
5 changed files with 201 additions and 140 deletions

View File

@@ -1,6 +1,9 @@
package ana
import "time"
import (
"fmt"
"time"
)
func predictionTimes(window time.Duration) []time.Time {
result := []time.Time{}
@@ -11,3 +14,23 @@ func predictionTimes(window time.Duration) []time.Time {
}
return result
}
func mustDateToTime(s string) time.Time {
result, err := dateToTime(s)
if err != nil {
panic(err)
}
return result
}
func dateToTime(s string) (time.Time, error) {
for _, layout := range []string{
"2006-01-02",
"2006-01",
} {
if t, err := time.ParseInLocation(layout, s, time.Local); err == nil {
return t, err
}
}
return time.Time{}, fmt.Errorf("no layout matching %q", s)
}