7 "github.com/pkg/errors"
10 // TimeLayout helps to parse a date string of the format YYYY-MM-DD
11 // Intended to be used with the following function:
12 // time.Parse(TimeLayout, date)
13 var TimeLayout = "2006-01-02" //this represents YYYY-MM-DD
15 // ParseDateRange parses a date range string of the format start:end
16 // where the start and end date are of the format YYYY-MM-DD.
17 // The parsed dates are time.Time and will return the zero time for
18 // unbounded dates, ex:
19 // unbounded start: :2000-12-31
20 // unbounded end: 2000-12-31:
21 func ParseDateRange(dateRange string) (startDate, endDate time.Time, err error) {
22 dates := strings.Split(dateRange, ":")
24 err = errors.New("bad date range, must be in format date:date")
27 parseDate := func(date string) (out time.Time, err error) {
31 out, err = time.Parse(TimeLayout, date)
34 startDate, err = parseDate(dates[0])
38 endDate, err = parseDate(dates[1])