Windows: Rufus: `ENV['TZ'] = 'Continent/City' 错误

Windows: Rufus: `ENV['TZ'] = 'Continent/City' Error

我想在我的 windows 机器上每小时安排一个作业 运行,为此使用了 rufus-scheduler。但是,由于下面解释的时区错误,我无法继续。

require 'rufus-scheduler'

require 'rufus-scheduler'
require 'tzinfo/data'

ENV['TZ'] = 'Asia/Chennai'

scheduler = Rufus::Scheduler::singleton

scheduler.every '1h' do
  # job here
end

我经常遇到这个错误。

 C:/Ruby22/lib/ruby/gems/2.2.0/gems/rufus-scheduler- 3.3.4/lib/rufus/scheduler/zotime.rb:41:in `initialize': cannot determine timezone from nil (etz:"Asia/India",tnz:"Asi",tzid:"constant") (ArgumentError)
 Try setting `ENV['TZ'] = 'Continent/City'` in your script (see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rufus-scheduler-  3.3.4/lib/rufus/scheduler/zotime.rb:206:in `new'
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rufus-scheduler- 3.3.4/lib/rufus/scheduler/zotime.rb:206:in `now'
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rufus-scheduler-3.3.4/lib/rufus/scheduler.rb:561:in `start'
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rufus-scheduler-3.3.4/lib/rufus/scheduler.rb:109:in `initialize'
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rufus-scheduler-3.3.4/lib/rufus/scheduler.rb:116:in `new'
    from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rufus-scheduler-3.3.4/lib/rufus/scheduler.rb:116:in `singleton'
    from scheduler.rb:9:in `<main>'

有人可以帮忙吗?

根据错误消息中链接的维基百科文章,印度(以及 IST)唯一有效的时区是 Asia/Kolkata

因此,如果您设置

ENV['TZ'] = 'Asia/Kolkata'

你应该得到正确的时区。

也就是说,首先设置操作系统以设置正确的本地时区可能是个好主意。这允许其他软件开箱即用地正常工作,而无需在每个软件中分别进行特定的时区配置。