This project is archived and is in readonly mode.
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
-
josh November 22nd, 2008 @ 06:56 PM
- Assigned user set to Geoff Buesing
- Tag set to activesupport, bug, core_ext
-
Geoff Buesing November 24th, 2008 @ 03:20 PM
- State changed from new to open
Sounds reasonable to have to_datetime recognize second fractions and numeric zone offsets -- I'd accept a patch for this.
-
Geoff Buesing February 8th, 2009 @ 06:24 PM
- State changed from open to stale
Please reopen if you have a patch for this
-
Jason Frey June 5th, 2009 @ 06:58 PM
- Tag changed from activesupport, bug, core_ext to activesupport, bug, core_ext, patch
Added timezone and fractional seconds support to String-Date conversions.
-
Repository June 8th, 2009 @ 02:17 AM
- State changed from stale to resolved
(from [1d9346428b3f12a42f717a7b1313cd4375d23e23]) String #to_time and #to_datetime: handle fractional seconds [#864 state:resolved] http://github.com/rails/rails/commit/1d9346428b3f12a42f717a7b1313cd...
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>
People watching this ticket
Attachments
Tags
Referenced by
- 864 String.to_datetime doesn't take into account timezone or second fractions (from [1d9346428b3f12a42f717a7b1313cd4375d23e23]) String ...