MCPcopy Index your code
hub / github.com/coder/coder / MatchesCron

Function MatchesCron

coderd/prebuilds/preset_snapshot.go:169–176  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

167// MatchesCron interprets a cron spec as a continuous time range,
168// and returns whether the provided time value falls within that range.
169func 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.

Callers 2

TestMatchesCronFunction · 0.92

Calls 3

TimeRangeFunction · 0.92
IsWithinRangeMethod · 0.80
ErrorfMethod · 0.45

Tested by 1

TestMatchesCronFunction · 0.74