OCI8 driver date "out of range"

Discussion in 'Ruby' started by Carlos Diaz, Feb 28, 2006.

  1. Carlos Diaz

    Carlos Diaz Guest

    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?
     
    Carlos Diaz, Feb 28, 2006
    #1
    1. Advertising

  2. Carlos Diaz

    Eric Hodel Guest

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

    > 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?


    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 - - http://blog.segment7.net
    This implementation is HODEL-HASH-9600 compliant

    http://trackmap.robotcoop.com
     
    Eric Hodel, Mar 1, 2006
    #2
    1. Advertising

  3. Carlos Diaz

    Carlos Diaz Guest

    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/browse_thread/thread/1ac3f69b=
    fabb8357

    Any help would be greatly appreciated.

    Thanks,
    Carlos

    On 2/28/06, Carlos Diaz <> wrote:
    > 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?
    >
    >
     
    Carlos Diaz, Mar 1, 2006
    #3
  4. Carlos Diaz

    Jeff Jones Guest

    > 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

    --
    Posted via http://www.ruby-forum.com/.
     
    Jeff Jones, Mar 1, 2006
    #4
  5. Hi,

    "Carlos Diaz" <> writes:

    > 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?


    Did you use OraDate#to_time?
    How about OraDate#to_date or OraDate#to_datetime?

    --
    KUBO Takehiro
    email:
    web: http://www.jiubao.org
    GnuPG fingerprint = 5F7B C8EF CA16 57D0 FDE1 9F47 C001 1F93 AC08 2262
     
    KUBO Takehiro, Mar 1, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    1
    Views:
    608
    Matthew Speed
    Nov 8, 2003
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,278
    Michael Borgwardt
    May 30, 2004
  3. Matt
    Replies:
    2
    Views:
    519
    Pete Becker
    Nov 8, 2003
  4. Matt
    Replies:
    3
    Views:
    724
    Richard Heathfield
    Nov 8, 2003
  5. Matt
    Replies:
    11
    Views:
    408
    Aaron Bertrand [MVP]
    Nov 8, 2003
Loading...

Share This Page