# YAML, Serialize and Date Formats problem

**URL:** <https://www.ruby-forum.com/t/yaml-serialize-and-date-formats-problem/139617>\
**Category:** Rails\
**Created:** [June 5, 2008, 2:59pm UTC](https://www.ruby-forum.com/t/yaml-serialize-and-date-formats-problem/139617 "2008-06-05T14:59:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![railsgeek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/82dd89/32.png) [@railsgeek](https://www.ruby-forum.com/u/railsgeek)\
**Post date:** [June 5, 2008, 2:59pm UTC](https://www.ruby-forum.com/t/yaml-serialize-and-date-formats-problem/139617/1 "2008-06-05T14:59:56Z")

</div>

I’m froma Spain, and was using DATE\_FORMATS to allow correct spanish  
format of date values. I’m using this at environment.rb file:

ActiveSupport::CoreExtensions:📅:Conversions::DATE\_FORMATS[:default]  
= ‘%d-%m-%Y’

But using serialize of attributes in ActiveRecord classes give me  
problems. I have a simple model like that:

class History \< ActiveRecord::Base

serialize :changes

end

Doing this:

History.create({:changes=\>{:my\_date=\>Date.today}})

I can’t read changes attribute like an Hash object, it always return a  
String object.

Digging deeper,…, I have found that the problem resides on the YAML  
library and the format of Date type.

Doing this:

Date.today.to\_yaml

=\> “— !timestamp 05-06-2008\n”

But doing this:

YAML.load(Date.today.to\_yaml)

ArgumentError: argument out of range

from /usr/lib/ruby/1.8/yaml.rb:133:in `utc’

from /usr/lib/ruby/1.8/yaml.rb:133:in `node\_import’

from /usr/lib/ruby/1.8/yaml.rb:133:in `load’

from /usr/lib/ruby/1.8/yaml.rb:133:in `load’

from (irb):1

Reading the YAML Cookbook at [http://yaml4r.sourceforge.net/co](http://yaml4r.sourceforge.net/co)…

I have found that YAML needs Date to be represented by its year, month  
and day in ISO8601 order.

Â¿Why in Rails the YAML/Serialize method don’t uses my date format?
