[Backgroundrb-devel] first_run timezone weirdness

Eden Li eden.li at gmail.com
Wed Oct 4 08:46:17 EDT 2006

If you're in a timezone with an abbreviation that map to more than one
timezone (eg, CST), first_run may not work as you expect it to.


$ irb -r time
irb(main):001:0> Time.now
=> Wed Oct 04 20:37:24 CST 2006
irb(main):002:0> Time.parse(Time.now.to_s)
=> Thu Oct 05 10:37:30 CST 2006

Notice the 14 extra hours... Time.parse converted the time thinking
CST meant -06:00 when my system time is actually on the +08:00 flavor
of CST.

So, BackgroundDRb::Rails#first_run creates a method that turns it from
a Time.now into a (practical) Time.parse(Time.now.to_s) which will
cause the first job to run 14 hours later than it should.

There a few ways to fix this, right now the hack I've come up with is
to pass in Time.now without the timezone letters so Time.parse will
convert the time using the local timezone:

def MyWorker < BackgroundDRb::Rails
  first_run Time.now.to_s.sub(/[A-Z]{3}/, '')

The other option is to patch backgroundrb to use UTC/GMT solely for
comparison -- convert the passed in time to GMT then stringify it for
the class eval'ed method -- then compare it against Time.now.gmtime in

I would gladly do this if only I could check out the branch from
rubyforge (is this down?)

More information about the Backgroundrb-devel mailing list