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

Method IsWithinRange

coderd/schedule/cron/cron.go:186–197  ·  view source on GitHub ↗

IsWithinRange interprets a cron spec as a continuous time range, and returns whether the provided time value falls within that range. For example, the expression "* 9-18 * * 1-5" represents a continuous time range from 09:00:00 to 18:59:59, Monday through Friday.

(t time.Time)

Source from the content-addressed store, hash-verified

184// For example, the expression "* 9-18 * * 1-5" represents a continuous time range
185// from 09:00:00 to 18:59:59, Monday through Friday.
186func (s Schedule) IsWithinRange(t time.Time) bool {
187 // Truncate to the beginning of the current minute.
188 currentMinute := t.Truncate(time.Minute)
189
190 // Go back 1 second from the current minute to find what the next scheduled time would be.
191 justBefore := currentMinute.Add(-time.Second)
192 next := s.Next(justBefore)
193
194 // If the next scheduled time is exactly at the current minute,
195 // then we are within the range.
196 return next.Equal(currentMinute)
197}
198
199var (
200 t0 = time.Date(1970, 1, 1, 1, 1, 1, 0, time.UTC)

Callers 2

MatchesCronFunction · 0.80
TestIsWithinRangeFunction · 0.80

Calls 3

NextMethod · 0.95
AddMethod · 0.65
EqualMethod · 0.45

Tested by 1

TestIsWithinRangeFunction · 0.64