MatchesCron interprets a cron spec as a continuous time range, and returns whether the provided time value falls within that range.
(cronExpression string, at time.Time)
| 167 | // MatchesCron interprets a cron spec as a continuous time range, |
| 168 | // and returns whether the provided time value falls within that range. |
| 169 | func MatchesCron(cronExpression string, at time.Time) (bool, error) { |
| 170 | sched, err := cron.TimeRange(cronExpression) |
| 171 | if err != nil { |
| 172 | return false, xerrors.Errorf("failed to parse cron expression: %w", err) |
| 173 | } |
| 174 | |
| 175 | return sched.IsWithinRange(at), nil |
| 176 | } |
| 177 | |
| 178 | // CalculateDesiredInstances returns the number of desired instances based on the provided time. |
| 179 | // If the time matches any defined prebuild schedule, the corresponding number of instances is returned. |