This project is archived and is in readonly mode.
to_yaml fails for DateTime objects
-
arash
Didn't have time to dig into the TimeWithZone source, so I am temporarily using this patch:
module ActiveSupport class TimeWithZone def datetime_to_i utc.is_a?(DateTime) ? utc.to_f : utc.to_i end alias_method :to_i, :datetime_to_i alias_method :hash, :datetime_to_i alias_method :tv_sec, :datetime_to_i end end -
Serguei Filimonov
- Tag changed from activerecord, yaml to activerecord, activesupport, patch, tested, yaml
Turns out the problem is more with the activesupport than with activerecord. Calling to_yaml on TimeWithZone calls #to_i on the class it's wrapping, which could be Time or DateTime. ActiveSupport, which provides the #to_f method, does not provide a #to_i on DateTime. The attached patch introduces the #to_i method for DateTime and is covered with the necessary tests on both activesupport and activerecord.
-
Michael Koziarski
- Assigned user set to Geoff Buesing
-
Serguei Filimonov
Also attached a patch for the master branch with the same fixes.
-
Geoff Buesing
- State changed from new to resolved
Applied in master and 2-3-stable. Thanks!
master: http://github.com/rails/rails/commit/2ae8300489aaaaaa65f50f3557090b...
2-3-stable: http://github.com/rails/rails/commit/754bbaaf37f21f51b345f88ca42b42... -
arash
thanks for taking care of this.
