Browse Source

Add location support

Wannes 9 years ago
parent
commit
5b7086674c
1 changed files with 8 additions and 1 deletions
  1. 8 1
      cron.go

+ 8 - 1
cron.go

@@ -19,6 +19,7 @@ type Cron struct {
 	snapshot chan []*Entry
 	running  bool
 	ErrorLog *log.Logger
+	location *time.Location
 }
 
 // Job is an interface for submitted cron jobs.
@@ -78,6 +79,7 @@ func New() *Cron {
 		snapshot: make(chan []*Entry),
 		running:  false,
 		ErrorLog: nil,
+		location: time.Now().Location(),
 	}
 }
 
@@ -125,6 +127,11 @@ func (c *Cron) Entries() []*Entry {
 	return c.entrySnapshot()
 }
 
+// SetLocations sets the time zone location
+func (c *Cron) SetLocation(location *time.Location) {
+	c.location = location
+}
+
 // Start the cron scheduler in its own go-routine.
 func (c *Cron) Start() {
 	c.running = true
@@ -147,7 +154,7 @@ func (c *Cron) runWithRecovery(j Job) {
 // access to the 'running' state variable.
 func (c *Cron) run() {
 	// Figure out the next activation times for each entry.
-	now := time.Now().Local()
+	now := time.Now().In(c.location)
 	for _, entry := range c.entries {
 		entry.Next = entry.Schedule.Next(now)
 	}