0

I have some lines of code in my Ruby script that gets the current date (mine is in GMT) and converts it to ET (Eastern Time).

I have this code in my Ruby script for that:

# get current time and date in ET
my_offset = 3600 * -5  # US Eastern

# find the zone with that offset
zone_name = ActiveSupport::TimeZone::MAPPING.keys.find do |name|
  ActiveSupport::TimeZone[name].utc_offset == my_offset
end
zone = ActiveSupport::TimeZone[zone_name]

time_locally = Time.now
time_in_zone = zone.at(time_locally)

The problem is it gives an error here (well, on this line): zone_name = ActiveSupport::TimeZone::MAPPING.keys.find do |name|: uninitialized constant ActiveSupport::TimeZone (NameError)

Anyone know what's wrong? I obtained this code segment from Stack Overflow, here.

Community
  • 1
  • 1
swiftcode
  • 3,039
  • 9
  • 39
  • 64

1 Answers1

2

Add

require 'active_support/time_with_zone'

After your other requires.

Chris Cherry
  • 28,118
  • 6
  • 68
  • 71
  • That solved that error, but now it gives a new error: `/Library/Ruby/Gems/1.8/gems/activesupport-3.0.0/lib/active_support/values/time_zone.rb:260:in at': undefined method in_time_zone' for Thu Dec 15 17:43:18 UTC 2011:Time (NoMethodError) from ruby ratings.rb:35` Line 35 in my code is: `time_in_zone = zone.at(time_locally)` – swiftcode Dec 15 '11 at 17:44