diff options
Diffstat (limited to 'ext/psych/lib/psych/visitors/yaml_tree.rb')
-rw-r--r-- | ext/psych/lib/psych/visitors/yaml_tree.rb | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb index 70db181a95..1f1acdbbcf 100644 --- a/ext/psych/lib/psych/visitors/yaml_tree.rb +++ b/ext/psych/lib/psych/visitors/yaml_tree.rb @@ -311,11 +311,27 @@ module Psych end private - def format_time time - if time.utc? - time.strftime("%Y-%m-%d %H:%M:%S.%9N Z") - else - time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z") + # '%:z' was no defined until 1.9.3 + if RUBY_VERSION < '1.9.3' + def format_time time + formatted = time.strftime("%Y-%m-%d %H:%M:%S.%9N") + + if time.utc? + formatted += " Z" + else + zone = time.strftime('%z') + formatted += " #{zone[0,3]}:#{zone[3,5]}" + end + + formatted + end + else + def format_time time + if time.utc? + time.strftime("%Y-%m-%d %H:%M:%S.%9N Z") + else + time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z") + end end end |