fleshing out comments

This commit is contained in:
gorhill 2013-08-30 08:26:18 -04:00
parent 7ea56a88b3
commit fc59c37234
1 changed files with 10 additions and 5 deletions

View File

@ -135,10 +135,15 @@ func (cronexpr *CronExpression) NextTime(fromTime time.Time) time.Time {
return fromTime return fromTime
} }
// First we need to ensure supplied time stamp matches // Since cronexpr.nextSecond()-cronexpr.nextMonth() expects that the
// supplied time stamp is a perfect match to the underlying cron
// expression, and since this function is an entry point where `fromTime`
// does not necessarily matches the underlying cron expression,
// we first need to ensure supplied time stamp matches
// the cron expression. If not, this means the supplied time // the cron expression. If not, this means the supplied time
// stamp might be between matching time stamps, thus we move // stamp falls in between matching time stamps, thus we move
// to closest matching time stamp without changing time stamp // to closest future matching time stamp without changing time
// stamp
// year // year
v := fromTime.Year() v := fromTime.Year()
@ -359,7 +364,7 @@ func (cronexpr *CronExpression) calculateActualDaysOfMonth(year, month int) []in
offset := 7 - int(timeOrigin.Weekday()) offset := 7 - int(timeOrigin.Weekday())
// days of week // days of week
// offset : (7 - day_of_week_of_1st_day_of_month) // offset : (7 - day_of_week_of_1st_day_of_month)
// target : (7 * week_of_month) + (offset + day_of_week) % 7 + 1 // target : 1 + (7 * week_of_month) + (offset + day_of_week) % 7
for w := 0; w <= 4; w += 1 { for w := 0; w <= 4; w += 1 {
for v, _ := range cronexpr.daysOfWeek { for v, _ := range cronexpr.daysOfWeek {
v := 1 + w*7 + (offset+v)%7 v := 1 + w*7 + (offset+v)%7
@ -370,7 +375,7 @@ func (cronexpr *CronExpression) calculateActualDaysOfMonth(year, month int) []in
} }
// days of week of specific week in the month // days of week of specific week in the month
// offset : (7 - day_of_week_of_1st_day_of_month) // offset : (7 - day_of_week_of_1st_day_of_month)
// target : (7 * week_of_month) + (offset + day_of_week) % 7 + 1 // target : 1 + (7 * week_of_month) + (offset + day_of_week) % 7
for v, _ := range cronexpr.specificWeekDaysOfWeek { for v, _ := range cronexpr.specificWeekDaysOfWeek {
v := 1 + 7*(v/7) + (offset+v)%7 v := 1 + 7*(v/7) + (offset+v)%7
if v <= lastDayOfMonth { if v <= lastDayOfMonth {