Skip to content

Commit

Permalink
Add location support
Browse files Browse the repository at this point in the history
  • Loading branch information
daft-panda committed Jun 6, 2016
1 parent 6f2e828 commit 5b70866
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -78,6 +79,7 @@ func New() *Cron {
snapshot: make(chan []*Entry),
running: false,
ErrorLog: nil,
location: time.Now().Location(),
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down

0 comments on commit 5b70866

Please sign in to comment.