Forum: Ruby OCI8 driver date "out of range"

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Beb0c27b5835d9b6aa289ecfc8f32e18?d=identicon&s=25 Carlos Diaz (Guest)
on 2006-02-28 17:13
(Received via mailing list)
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?
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2006-03-01 03:51
(Received via mailing list)
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 Hodel - drbrain@segment7.net - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com
Beb0c27b5835d9b6aa289ecfc8f32e18?d=identicon&s=25 Carlos Diaz (Guest)
on 2006-03-01 04:05
(Received via mailing list)
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 Haines 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/brow...

Any help would be greatly appreciated.

Thanks,
Carlos
C728d93eb5205cf20cac0c2928b0ad62?d=identicon&s=25 Jeff Jones (rurounijones)
on 2006-03-01 15:29
> 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
6ece05caebbfa91944047629101bc5ea?d=identicon&s=25 KUBO Takehiro (Guest)
on 2006-03-01 16:00
(Received via mailing list)
Hi,

"Carlos Diaz" <crdiaz324@gmail.com> 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?
This topic is locked and can not be replied to.