diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-10-06 20:12:00 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-10-06 20:12:00 -0700 |
commit | 2cf1f822b5e44308bb9e5af8ee4d75cfda0b4d9e (patch) | |
tree | 47c1056052e8ee61f73dc086586da521fe1f9bb8 /lib | |
parent | 3b4656645f551f0ebe8b5c7e8660992bc88de123 (diff) | |
download | psych-2cf1f822b5e44308bb9e5af8ee4d75cfda0b4d9e.zip |
times now round trip
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 2 | ||||
-rw-r--r-- | lib/psych/visitors/yast_builder.rb | 11 |
2 files changed, 12 insertions, 1 deletions
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 |