This project is archived and is in readonly mode.

#864 ✓resolved
Yair Halevi (Spock)

String.to_datetime doesn't take into account timezone or second fractions

Reported by Yair Halevi (Spock) | August 19th, 2008 @ 11:50 PM | in 2.x

The method ActiveSupport::CoreExtensions::String::Conversions::to_datetime (in file activesupport/core_ext/string/conversions.rb) doesn't take into account timezone or second fractions in some standard date formats.

For example, a standard XML Schema dateTime representation isn't parsed correctly:



>> s='2008-08-04T13:10:42.312+03:00'

=> "2008-08-04T13:10:42.312+03:00"

>> d=s.to_datetime

=> Mon, 04 Aug 2008 13:10:42 +0000

>> d.strftime('%FT%T.%L%:z')

=> "2008-08-04T13:10:42.000+00:00"

I've encountered this problem when using the soap4r library with Rails. soap4r looks for a to_datetime method as a first option to parse dates in SOAP responses (presumably since Ruby 1.9 supports such methods, I'm not very familiar with 1.9). Since Rails provides this for the String class, soap4r uses the Rails implementation, which loses information and provides incorrect dates.

Note that DateTime.parse does perform the correct parsing. I'm not sure why the Rails implementation discards the fraction and timezone information.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Referenced by

Pages