[ruby-core:32974] Re: [Ruby 1.9-Bug#4005] YAML fails to roundtrip Time objects

From: Aaron Patterson <aaron@...>
Date: 2010-10-30 14:07:52 UTC
List: ruby-core #32974
On Sat, Oct 30, 2010 at 11:31:15AM +0900, Peter Weldon wrote:
> Issue #4005 has been updated by Peter Weldon.
> 
> 
> :~$ rvm exec ruby -v -ryaml -e 't0 = Time.now; p t0; p YAML::load(YAML::dump(t0)) == t0'
> ruby 1.9.3dev (2010-10-30 trunk 29630) [i686-linux]
> 2010-10-30 02:30:09 +0000
> false
> ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux]
> Sat Oct 30 02:30:10 +0000 2010
> true
> ruby 1.9.1p378 (2010-01-10 revision 26273) [i686-linux]
> 2010-10-30 02:30:10 +0000
> false
> ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
> 2010-10-30 02:30:11 +0000
> false
> 
> ~$ printenv | grep TZ
> ~$

I'm not able to reproduce this with Syck.  Can you try with Psych
instead?  Like this:

  ruby -v -ryaml -e 'YAML::ENGINE.yamler = "psych"; t0 = Time.now; p t0; p YAML::load(YAML::dump(t0)) == t0'

I suspect your error is due to fractional second support.  Observe the
output of Syck compared to Psych:

  ### Using Syck
  $ ruby -v -ryaml -e 't0 = Time.now; p t0; p YAML::dump(t0)'

  "--- 2010-10-30 07:05:46.535362 -07:00\n"

  ### Using Psych
  ruby -v -ryaml -e 'YAML::ENGINE.yamler = "psych"; t0 = Time.now; p t0; p YAML::dump(t0)'

  "--- 2010-10-30 07:06:48.118999000 -07:00\n...\n"

-- 
Aaron Patterson
http://tenderlovemaking.com/

In This Thread