# Problem opening the time class

**URL:** <https://www.ruby-forum.com/t/problem-opening-the-time-class/180932>\
**Category:** Ruby\
**Created:** [December 31, 2009, 10:52pm UTC](https://www.ruby-forum.com/t/problem-opening-the-time-class/180932 "2009-12-31T22:52:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cristie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a3d4f5/32.png) [@cristie](https://www.ruby-forum.com/u/cristie)\
**Post date:** [December 31, 2009, 10:52pm UTC](https://www.ruby-forum.com/t/problem-opening-the-time-class/180932/1 "2009-12-31T22:52:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cristie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a3d4f5/32.png) [@cristie](https://www.ruby-forum.com/u/cristie)\
**Post date:** [January 1, 2010, 8:35pm UTC](https://www.ruby-forum.com/t/problem-opening-the-time-class/180932/2 "2010-01-01T20:35:37Z")

</div>

On Dec 31 2009, 4:52 pm, Cris S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> 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
> 
> Posted viahttp://www.ruby-forum.com/.

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?

---

<div class="post-metadata">

**Author:** ![cristie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a3d4f5/32.png) [@cristie](https://www.ruby-forum.com/u/cristie)\
**Post date:** [January 4, 2010, 3:18pm UTC](https://www.ruby-forum.com/t/problem-opening-the-time-class/180932/3 "2010-01-04T15:18:00Z")

</div>

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

pharrington wrote:

> On Dec 31 2009, 4:52ï¿½pm, Cris S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > ## ï¿½ ï¿½ 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
> > 
> > Posted viahttp://www.ruby-forum.com/.
> 
> 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?

---

<div class="post-metadata">

**Author:** ![cristie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a3d4f5/32.png) [@cristie](https://www.ruby-forum.com/u/cristie)\
**Post date:** [January 4, 2010, 5:30pm UTC](https://www.ruby-forum.com/t/problem-opening-the-time-class/180932/4 "2010-01-04T17:30:19Z")

</div>

> > require ‘time’  
> > =\> true
> 
> > Time::ZoneOffset  
> > NameError: uninitialized constant Time::ZoneOffset  
> > from (irb):2
> 
> > (class \<\< Time; self; end)::ZoneOffset  
> > =\> {“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}
