Search code examples
rubynulltimezonerufus-schedulerargument-error

Ruby Cannot Determine Timezone From Nil (Argument Error)


I wrote some code with ruby. I get this error when I try to run the code:

/Users/macbook/.rvm/gems/ruby-2.2.2/gems/rufus-scheduler-3.3.3/lib/rufus/scheduler/zotime.rb:41:
  in `initialize':
  cannot determine timezone from nil (etz:nil,tnz:"+03",tzid:nil) (ArgumentError)

Edit:

I'm using ebooks gem. I only added consumer keys and access tokens. My .rb file is:

require 'twitter_ebooks'

class MyBot < Ebooks::Bot
  def configure
    self.consumer_key = 'Consumer Key'
    self.consumer_secret = 'Consumer Secret'
    self.blacklist = ['tnietzschequote']

    self.delay_range = 1..6
  end

  def on_startup
    scheduler.every '24h' do
    end
  end

  def on_message(dm)
  end

  def on_follow(user)
  end

  def on_mention(tweet)
  end

  def on_timeline(tweet)
  end

  def on_favorite(user, tweet)
  end

  def on_retweet(tweet)
  end
end

MyBot.new("twitter_id") do |bot|
  bot.access_token = "Access Token" # Token connecting the app to this account
  bot.access_token_secret = "Access Token Secret" 
end

I'll be glad if someone help me.


Solution

  • setting explicitly the ENV['TZ'] before the scheduler instantiation

    ENV['TZ'] = 'Asia/Shanghai' # your time zone 
      # or
    ENV['TZ'] = Time.zone.tzinfo.identifier
    scheduler = Rufus::Scheduler.new
    # ...
    

    should solve your issue :)

    See https://github.com/jmettraux/rufus-scheduler#i-get-zotimerb41in-initialize-cannot-determine-timezone-from-nil