Beispiel #1
0
// returns the first day from the date, depending on the group
func (d Generator) FirstFromDate(date epochdate.Date) epochdate.Date {
	switch d.Group {
	case WEEK:
		// first date is the previous monday of the week
		wd := date.UTC().Weekday()
		if wd > d.FirstDayOfWeek {
			return date - epochdate.Date(wd) + epochdate.Date(d.FirstDayOfWeek)
		} else if wd < d.FirstDayOfWeek {
			return date - 6 + epochdate.Date(wd)
		}
	case MONTH:
		// first day of the month
		year, month, _ := date.Date()
		ret, _ := epochdate.NewFromDate(year, month, 1)
		return ret
	}
	return date
}