1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| func timeByInterval(t time.Time, interval string) time.Time { if interval == "day" { return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location()) } if interval == "week" { t = t.AddDate(0, 0, int(t.Weekday())-1) return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location()) } if interval == "month" { return time.Date(t.Year(), t.Month(), 0, 0, 0, 0, 0, t.Location()) } return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location()) }
|