From 2cf1f822b5e44308bb9e5af8ee4d75cfda0b4d9e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 6 Oct 2009 20:12:00 -0700 Subject: times now round trip --- lib/psych/visitors/to_ruby.rb | 2 +- lib/psych/visitors/yast_builder.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index b4e33ed..40236ce 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -40,7 +40,7 @@ module Psych date, time = *(lexeme.split(/[ tT]/, 2)) (yy, m, dd) = date.split('-').map { |x| x.to_i } - md = time.match /(\d+:\d+:\d+)(\.\d*)?\s*(Z|[-+]\d+(:\d\d)?)?/ + md = time.match(/(\d+:\d+:\d+)(\.\d*)?\s*(Z|[-+]\d+(:\d\d)?)?/) (hh, mm, ss) = md[1].split(':').map { |x| x.to_i } diff --git a/lib/psych/visitors/yast_builder.rb b/lib/psych/visitors/yast_builder.rb index 9111f8b..1f1eae4 100644 --- a/lib/psych/visitors/yast_builder.rb +++ b/lib/psych/visitors/yast_builder.rb @@ -21,6 +21,17 @@ module Psych raise TypeError, "Can't dump #{target.class}" end + def visit_Time o + formatted = o.strftime("%Y-%m-%d %H:%M:%S") + if o.utc? + formatted += ".%06dZ" % [o.usec] + else + formatted += ".%06d %d:00" % [o.usec, o.gmt_offset / 3600] + end + + append Nodes::Scalar.new formatted + end + def visit_Date o append Nodes::Scalar.new o.to_s end -- cgit v1.2.3