MCPcopy
hub / github.com/robfig/cron / TestLocalTimezone

Function TestLocalTimezone

cron_test.go:297–322  ·  view source on GitHub ↗

Test that the cron is run in the local time zone (as opposed to UTC).

(t *testing.T)

Source from the content-addressed store, hash-verified

295
296// Test that the cron is run in the local time zone (as opposed to UTC).
297func TestLocalTimezone(t *testing.T) {
298 wg := &sync.WaitGroup{}
299 wg.Add(2)
300
301 now := time.Now()
302 // FIX: Issue #205
303 // This calculation doesn't work in seconds 58 or 59.
304 // Take the easy way out and sleep.
305 if now.Second() >= 58 {
306 time.Sleep(2 * time.Second)
307 now = time.Now()
308 }
309 spec := fmt.Sprintf("%d,%d %d %d %d %d ?",
310 now.Second()+1, now.Second()+2, now.Minute(), now.Hour(), now.Day(), now.Month())
311
312 cron := newWithSeconds()
313 cron.AddFunc(spec, func() { wg.Done() })
314 cron.Start()
315 defer cron.Stop()
316
317 select {
318 case <-time.After(OneSecond * 2):
319 t.Error("expected job fires 2 times")
320 case <-wait(wg):
321 }
322}
323
324// Test that the cron is run in the given time zone (as opposed to local).
325func TestNonLocalTimezone(t *testing.T) {

Callers

nothing calls this directly

Calls 7

newWithSecondsFunction · 0.85
waitFunction · 0.85
AddFuncMethod · 0.80
DoneMethod · 0.80
StartMethod · 0.80
StopMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected