# DateTime yaml bug

**URL:** <https://www.ruby-forum.com/t/datetime-yaml-bug/113082>\
**Category:** Ruby\
**Created:** [August 27, 2007, 12:10pm UTC](https://www.ruby-forum.com/t/datetime-yaml-bug/113082 "2007-08-27T12:10:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![seeweer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e5b9ba/32.png) [@seeweer](https://www.ruby-forum.com/u/seeweer)\
**Post date:** [August 27, 2007, 12:10pm UTC](https://www.ruby-forum.com/t/datetime-yaml-bug/113082/1 "2007-08-27T12:10:44Z")

</div>

Hi,

does anybody know a quick fix to the DateTime or Yaml bug

YAML::load(DateTime.now.to\_yaml).class  
=\> Time

Thx

Artur

---

<div class="post-metadata">

**Author:** ![seeweer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e5b9ba/32.png) [@seeweer](https://www.ruby-forum.com/u/seeweer)\
**Post date:** [August 28, 2007, 11:31am UTC](https://www.ruby-forum.com/t/datetime-yaml-bug/113082/2 "2007-08-28T11:31:41Z")

</div>

On 27 Aug., 12:09, Artur M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> does anybody know a quick fix to the DateTime or Yaml bug
> 
> YAML::load(DateTime.now.to\_yaml).class  
> =\> Time

Nobody out there to answer the question? The Problem is  
not only, that the class switches to Time, but also that  
the read in date is wrong by an week (and the time differs too):

> dt= DateTime.now  
> =\> #\<DateTime: 21205505265589/8640000,1/12,2299161\>

> dt.to\_yaml  
> =\> “— !timestamp 2007-08-28T11:17:35+0200\n”

> res= YAML::load(dt.to\_yaml)  
> =\> Mon Aug 20 05:17:35 Westeurop ische Normalzeit 2007

> res.to\_yaml  
> =\> “— 2007-08-20 05:17:35 +02:00\n”

using Marshal

Marshal.load(Marshal.dump(dt))

gives the right solution (both the class and the data in it are  
exactly the same), but I really wanted to stick to yaml …

Artur

---

<div class="post-metadata">

**Author:** ![seeweer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e5b9ba/32.png) [@seeweer](https://www.ruby-forum.com/u/seeweer)\
**Post date:** [August 28, 2007, 12:00pm UTC](https://www.ruby-forum.com/t/datetime-yaml-bug/113082/3 "2007-08-28T12:00:44Z")

</div>

From: Artur M. [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

# \> does anybody know a quick fix to the DateTime or Yaml bug

# \>

# \> YAML::load(DateTime.now.to\_yaml).class

# \> =\> Time

cannot help you, but only say that i can replicate the behaviour here  
too. someone complained too  
[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/262969](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/262969)

i think it’s a bug. stick to marshall in the meantime.

kind regards -botp

---

<div class="post-metadata">

**Author:** ![seeweer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e5b9ba/32.png) [@seeweer](https://www.ruby-forum.com/u/seeweer)\
**Post date:** [September 9, 2007, 11:47pm UTC](https://www.ruby-forum.com/t/datetime-yaml-bug/113082/4 "2007-09-09T23:47:19Z")

</div>

On Aug 27, 2007, at 03:10, Artur M. wrote:

> does anybody know a quick fix to the DateTime or Yaml bug
> 
> YAML::load(DateTime.now.to\_yaml).class  
> =\> Time

Please file a bug in the ruby tracker on RubyForge.

Also:

irb(main):003:0\> DateTime.parse ‘3000/01/01 01:01:01’  
=\> #\<DateTime: 243370443661/86400,0,2299161\>  
irb(main):004:0\> dt = \_  
=\> #\<DateTime: 243370443661/86400,0,2299161\>  
irb(main):005:0\> YAML.load dt.to\_yaml  
ArgumentError: time out of range
