date/format.rb fix

B

Brad Hilton

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.
(e-mail address removed)
 
N

NAKAMURA, Hiroshi

Hi,
From: "Brad Hilton" <[email protected]>
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
 
B

Brad Hilton

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. :) 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top