Date/format.rb fix

Hello,

The _parse() function of date/format.rb does not handle fractions of
seconds. Eg, the string

2004-02-12 12:23:45.581297-07

causes the parser to miss the timezone offset. Postgresql returns
timestamp columns like this, thus breaking ruby-dbi.

A simple change to the regex can fix this:

— date/format.rb.orig 2004-02-24 12:07:42.000000000 -0800
+++ date/format.rb 2004-02-24 12:03:12.000000000 -0800
@@ -236,7 +236,7 @@ class Date

  # time
  if str.sub!(
  •           /(\d+):(\d+)(?::(\d+))?
    
  •           /(\d+):(\d+)(?::(\d+)(?:\.\d+)?)?
                (?:
                  \s*
                  ([ap])(?:m\b|\.m\.)
    

Would someone please consider applying this fix?

Thanks,

Brad Hilton
VPOP Technologies, Inc.
bhilton@vpop.net

Hi,

From: “Brad Hilton” bhilton@vpop.net
Sent: Wednesday, February 25, 2004 5:19 AM

The _parse() function of date/format.rb does not handle fractions of
seconds. Eg, the string

2004-02-12 12:23:45.581297-07

causes the parser to miss the timezone offset.

You got that right.

A simple change to the regex can fix this:

  •           /(\d+):(\d+)(?::(\d+))?
    
  •           /(\d+):(\d+)(?::(\d+)(?:\.\d+)?)?
    

Drop fractions?

/(\d+):(\d+)(?::(\d+(?:.\d+)?))?

Could be better but I don’t know how we treat $3 string.
$3 is converted to Integer via to_i now. Float? Rational?

The author Funaba-san merely seen in this ML. I’ll forward it
some later date.

Regards,
// NaHi

NAKAMURA, Hiroshi wrote:

The _parse() function of date/format.rb does not handle fractions of
seconds. Eg, the string

2004-02-12 12:23:45.581297-07

causes the parser to miss the timezone offset.

A simple change to the regex can fix this:

  •           /(\d+):(\d+)(?::(\d+))?
    
  •           /(\d+):(\d+)(?::(\d+)(?:\.\d+)?)?
    

Drop fractions?

/(\d+):(\d+)(?::(\d+(?:.\d+)?))?

Could be better but I don’t know how we treat $3 string.
$3 is converted to Integer via to_i now. Float? Rational?

I wasn’t sure - that’s why I updated the regex to simply drop the
fraction. :slight_smile: Dropping the fraction is not ideal, but at least people
won’t have any unpleasant surprises if they are expecting the current
behavior (converting the seconds to an int).

The author Funaba-san merely seen in this ML. I’ll forward it
some later date.

Thank you.

-Brad