瀏覽代碼

Fixed remaining time.Now().Local()

Wannes 9 年之前
父節點
當前提交
17583deb80
共有 2 個文件被更改,包括 3 次插入4 次删除
  1. 1 1
      cron.go
  2. 2 3
      cron_test.go

+ 1 - 1
cron.go

@@ -196,7 +196,7 @@ func (c *Cron) run() {
 
 		case newEntry := <-c.add:
 			c.entries = append(c.entries, newEntry)
-			newEntry.Next = newEntry.Schedule.Next(time.Now().Local())
+			newEntry.Next = newEntry.Schedule.Next(time.Now().In(c.location))
 
 		case <-c.snapshot:
 			c.snapshot <- c.entrySnapshot()

+ 2 - 3
cron_test.go

@@ -116,9 +116,9 @@ func TestAddWhileRunningWithDelay(t *testing.T) {
 	defer cron.Stop()
 	time.Sleep(5 * time.Second)
 	var calls = 0
-	cron.AddFunc("* * * * * *", func() { calls += 1 });
+	cron.AddFunc("* * * * * *", func() { calls += 1 })
 
-	<- time.After(ONE_SECOND)
+	<-time.After(ONE_SECOND)
 	if calls != 1 {
 		fmt.Printf("called %d times, expected 1\n", calls)
 		t.Fail()
@@ -237,7 +237,6 @@ func TestLocalTimezone(t *testing.T) {
 	}
 }
 
-
 // Test that the cron is run in the given time zone (as opposed to local).
 func TestNonLocalTimezone(t *testing.T) {
 	wg := &sync.WaitGroup{}