package ana

import (
	"fmt"
	"time"
)

func predictionTimes(window time.Duration) []time.Time {
	result := []time.Time{time.Now()}
	last := time.Now()
	for last.Before(time.Now().Add(window)) {
		last = last.Add(-1 * time.Hour * 24 * time.Duration(last.Day())).Add(time.Hour * 24 * 33)
		result = append(result, last)
	}
	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)
}
