// CalculateTimes returns a list of all times the given event will take place, using its RecurRule information.
CalculateTimes returns a list of all times the given event will take place, using its RecurRule information.
// CalculateTimes returns a list of all times the given event will take place using its RecurRule information .
func (e *Event) CalculateTimes(until time.Time) ([]time.Time, error) {
	eventStartTime := time.Unix(int64(e.Start), 0).UTC()
	if e.StartTimezone != "" {
		location, err := time.LoadLocation(e.StartTimezone)
		if err != nil {
			return nil, err
		}
		eventStartTime = eventStartTime.In(location)
	}
	eventTimes := []time.Time{}
	eventTimes = append(eventTimes, eventStartTime)
	if e.RecurRule != nil {
		currentTime := eventStartTime
		for currentTime.Before(until) {
			years := 0
			months := 0
			days := 0
			if e.RecurRule.Frequency == RecurFrequencyDaily {
				days = 1
			} else if e.RecurRule.Frequency == RecurFrequencyWeekly {
				days = 7
			} else if e.RecurRule.Frequency == RecurFrequencyMonthly {
				months = 1
			} else { 
				years = 1
			}
			years *= e.RecurRule.Interval
			months *= e.RecurRule.Interval
			days *= e.RecurRule.Interval
			previousTime := currentTime
			currentTime = currentTime.AddDate(years, months, days)
			if previousTime == currentTime {
				break
			}
			if e.RecurRule.UntilString != "" {
				ruleUntil := e.RecurRule.Until
				if ruleUntil.Sub(currentTime) < -24*time.Hour {
					break
				}
			}
			eventTimes = append(eventTimes, currentTime)
		}
	}
	return eventTimes, nil
}
func ( e * Event ) CalculateTimes ( until time . Time ) ( [ ] time . Time , error ) { eventStartTime := time . Unix ( int64 ( e . Start ) , 0 ) . UTC ( ) if e . StartTimezone != " " { location , err := time . LoadLocation ( e . StartTimezone ) if err != nil { return nil , err } eventStartTime = eventStartTime . In ( location ) } eventTimes := [ ] time . Time { } eventTimes = append ( eventTimes , eventStartTime ) if e . RecurRule != nil { currentTime := eventStartTime for currentTime . Before ( until ) { years := 0 months := 0 days := 0 if e . RecurRule . Frequency == RecurFrequencyDaily { days = 1 } else if e . RecurRule . Frequency == RecurFrequencyWeekly { days = 7 } else if e . RecurRule . Frequency == RecurFrequencyMonthly { months = 1 } else { years = 1 } years *= e . RecurRule . Interval months *= e . RecurRule . Interval days *= e . RecurRule . Interval previousTime := currentTime currentTime = currentTime . AddDate ( years , months , days ) if previousTime == currentTime { break } if e . RecurRule . UntilString != " " { ruleUntil := e . RecurRule . Until if ruleUntil . Sub ( currentTime ) < - 24 * time . Hour { break } } eventTimes = append ( eventTimes , currentTime ) } } return eventTimes , nil }
CalculateTimes returns a list of all times the given event will take place, using its RecurRule information.
CalculateTimes returns a list of all times the given event will take place using its RecurRule information .
// obviously it has to happen at least once // if e.RecurRule.Frequency == RecurFrequencyYearly { // we're not making progress, escape