# OCI8 driver date "out of range"

**URL:** <https://www.ruby-forum.com/t/oci8-driver-date-out-of-range/74782>\
**Category:** Ruby\
**Created:** [February 28, 2006, 5:13pm UTC](https://www.ruby-forum.com/t/oci8-driver-date-out-of-range/74782 "2006-02-28T17:13:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carlos\_Diaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9c0ed/32.png) [@Carlos\_Diaz](https://www.ruby-forum.com/u/Carlos_Diaz)\
**Post date:** [February 28, 2006, 5:13pm UTC](https://www.ruby-forum.com/t/oci8-driver-date-out-of-range/74782/1 "2006-02-28T17:13:21Z")

</div>

Hi all,

I am building an applications that access an existing database that  
has dates in the future…as far ahead as 2106. However, when I try  
to access the data in those columns (I’m using the OCI8 driver), I get  
the following error:

RangeError in Tools#search

out of range of Time (expect between 1970-01-01 00:00:00 UTC and  
2037-12-31 23:59:59, but 2106-02-22 15:17:54 EST)

Anyone familiar with this? How can I resolve?

---

<div class="post-metadata">

**Author:** ![Carlos\_Diaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9c0ed/32.png) [@Carlos\_Diaz](https://www.ruby-forum.com/u/Carlos_Diaz)\
**Post date:** [March 1, 2006, 4:05am UTC](https://www.ruby-forum.com/t/oci8-driver-date-out-of-range/74782/2 "2006-03-01T04:05:38Z")

</div>

Ok, after doing some research on this, it looks like the problem isn’t  
with OCI8 but it appears to be more directly related to a conversion  
problem. Specifically when oci8.rb tries to covert the Oracle Date  
into Time.local. This is because Time relies on seconds since 1970  
and I think the 32 bit operating system does not have enough room to  
store a date with that many seconds since 1970 (please correct me if  
I’m wrong). For example, if I go to irb and type: Time.local(2106,  
02, 22, 15, 17, 54), that should produce th date below, but it  
actually give me a ArgumentError: time out of range.

Has anyone else found a way to work around this problem? I found the  
following link where Kirk H. seemed to think this was not a  
difficult fix. Just don’t know if anyone has gotten around to writing  
it:

[http://groups.google.com/group/comp.lang.ruby/browse\_thread/thread/1ac3f69bfabb8357](http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/1ac3f69bfabb8357)

Any help would be greatly appreciated.

Thanks,  
Carlos

---

<div class="post-metadata">

**Author:** ![Carlos\_Diaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9c0ed/32.png) [@Carlos\_Diaz](https://www.ruby-forum.com/u/Carlos_Diaz)\
**Post date:** [March 1, 2006, 3:51am UTC](https://www.ruby-forum.com/t/oci8-driver-date-out-of-range/74782/3 "2006-03-01T03:51:15Z")

</div>

On Feb 28, 2006, at 8:11 AM, Carlos Diaz wrote:

> Anyone familiar with this? How can I resolve?  
> Either

Use Date instead of Time.

Or

Upgrade to an OS (and possibly machine) with a 64-bit time\_t:

$ ruby -v -rtime -e ‘p Time.parse(“2106-02-22 15:17:54 EST”)’  
ruby 1.8.4 (2005-12-24) [amd64-freebsd6]  
Mon Feb 22 12:17:54 PST 2106

Note that FreeBSD on x86 has a 32 bit time\_t:

$ ruby -v -rtime -e ‘p Time.parse(“2106-02-22 15:17:54 EST”)’  
ruby 1.8.2 (2004-12-25) [i386-freebsd5]  
/usr/local/lib/ruby/1.8/time.rb:162:in `utc': time out of range (ArgumentError) from /usr/local/lib/ruby/1.8/time.rb:162:in `parse’  
from -e:1

–  
Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![Carlos\_Diaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9c0ed/32.png) [@Carlos\_Diaz](https://www.ruby-forum.com/u/Carlos_Diaz)\
**Post date:** [March 1, 2006, 3:29pm UTC](https://www.ruby-forum.com/t/oci8-driver-date-out-of-range/74782/4 "2006-03-01T15:29:28Z")

</div>

> Any help would be greatly appreciated.
> 
> Thanks,  
> Carlos

I am sure this is bad, evil, probably wrong as hell thing to to but:

I am using a simple simple program that suffers from this problem. I  
only wanted the Date values, I didn’t care about the time value as it  
was always 00:00.

I cannot change the table structure and I am not actively using the  
value (I am going from oracle to a RoR view with \<%= class.date %\>, no  
processing)

I browsed around for ages and found someone talking about messing with  
the oci8.rb file OraDate function.

I changed

class OraDate  
def to\_time  
begin  
Time.local(year, month, day, hour, minute, second)  
rescue ArgumentError  
msg = format(“out of range of Time (expect between 1970-01-01  
00:00:00 UTC and 2037-12-31 23:59:59, but %04d-%02d-%02d %02d:%02d:%02d  
%s)”, year, month, day, hour, minute, second, Time.at(0).zone)  
raise RangeError.new(msg)  
end  
end

To

class OraDate  
def to\_time  
begin  
Time.local(year, month, day, hour, minute, second)  
rescue ArgumentError  
Date.new(year, month, day)  
end  
end

So I guess I am in essence saying “If to\_time fails, use to\_date”…

It worked for me in a trivial application and I am sure I have condemned  
myself to hell for using it so be careful. I have no idea what hte  
ramifications are and how it would cope in a more complex program.

It might cost you your soul 😉

Jeff

---

<div class="post-metadata">

**Author:** ![Carlos\_Diaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9c0ed/32.png) [@Carlos\_Diaz](https://www.ruby-forum.com/u/Carlos_Diaz)\
**Post date:** [March 1, 2006, 4:00pm UTC](https://www.ruby-forum.com/t/oci8-driver-date-out-of-range/74782/5 "2006-03-01T16:00:24Z")

</div>

Hi,

“Carlos Diaz” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> 2037-12-31 23:59:59, but 2106-02-22 15:17:54 EST)
> 
> Anyone familiar with this? How can I resolve?

Did you use OraDate#to\_time?  
How about OraDate#to\_date or OraDate#to\_datetime?
