problem opening the time class

C

Cris Shupp

All,

I am trying to open the Time class to add the following method.
I am always getting this error:
NameError: uninitialized constant Time::ZoneOffset

when referencing ZoneOffset. What am I doing wrong?


class Time
def self.offset_to_zone(offset)
offset = offset.to_i
ZoneOffset.each_pair do |time_zone, zone_offset| #ERROR OCCURS
HERE!!!
return time_zone if (zone_offset == offset)
end
raise ArgumentError, "Illegal arguments! The offset " <<
offset.to_s << " is unknown."
end
end
 
P

pharrington

All,

I am trying to open the Time class to add the following method.
I am always getting this error:
NameError: uninitialized constant Time::ZoneOffset

when referencing ZoneOffset.  What am I doing wrong?

class Time
  def self.offset_to_zone(offset)
    offset = offset.to_i
    ZoneOffset.each_pair do |time_zone, zone_offset| #ERROR OCCURS
HERE!!!
      return time_zone if (zone_offset == offset)
    end
    raise ArgumentError, "Illegal arguments!  The offset " <<
offset.to_s << " is unknown."
  end
end

As the error status, there is no Time::ZoneOffset constant....

Are you copying/pasting random code from somewhere?
If not, what is ZoneOffset even supposed to be?
 
C

Cris Shupp

pharrington,

Thanks for the reply.

From time.rb (the standard library)

class Time
class << Time

ZoneOffset = {
'UTC' => 0,
# ISO 8601
'Z' => 0,
# RFC 822
'UT' => 0, 'GMT' => 0,
'EST' => -5, 'EDT' => -4,
'CST' => -6, 'CDT' => -5,
'MST' => -7, 'MDT' => -6,
'PST' => -8, 'PDT' => -7,
# Following definition of military zones is original one.
# See RFC 1123 and RFC 2822 for the error in RFC 822.
'A' => +1, 'B' => +2, 'C' => +3, 'D' => +4, 'E' => +5, 'F' =>
+6,
'G' => +7, 'H' => +8, 'I' => +9, 'K' => +10, 'L' => +11, 'M' =>
+12,
'N' => -1, 'O' => -2, 'P' => -3, 'Q' => -4, 'R' => -5, 'S' =>
-6,
'T' => -7, 'U' => -8, 'V' => -9, 'W' => -10, 'X' => -11, 'Y' =>
-12,
}


I am trying to access the constant within.

Thanks,

Cris
 
B

Brian Candler

require 'time'
=> trueNameError: uninitialized constant Time::ZoneOffset
from (irb):2=> {"V"=>-9, "K"=>10, "PDT"=>-7, "W"=>-10, "L"=>11, "A"=>1, "X"=>-11,
"M"=>12, "B"=>2, "Y"=>-12, "N"=>-1, "C"=>3, "MST"=>-7, "GMT"=>0,
"O"=>-2, "D"=>4, "CST"=>-6, "Z"=>0, "UTC"=>0, "P"=>-3, "E"=>5, "Q"=>-4,
"F"=>6, "PST"=>-8, "EST"=>-5, "R"=>-5, "G"=>7, "MDT"=>-6, "S"=>-6,
"H"=>8, "CDT"=>-5, "T"=>-7, "I"=>9, "UT"=>0, "U"=>-8, "EDT"=>-4}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,048
Members
48,769
Latest member
Clifft

Latest Threads

Top