diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-09-08 07:04:59 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-08 07:04:59 +0900 |
commit | 78a0517af4244e033b22e3df2bc50949d688e0b5 (patch) | |
tree | c3e62f6a6c6bd9cf61ef1c752b60d9ad3750771b | |
parent | 54dbf51dbc98f55372d55962006ec96fd21e8097 (diff) | |
parent | ff200f107285a6083773a9fdf063206b07f8a81b (diff) | |
download | psych-78a0517af4244e033b22e3df2bc50949d688e0b5.tar.gz |
Merge pull request #576 from ruby/bump-3-3-3v3.3.3
Bump up v3.3.3
-rw-r--r-- | .github/workflows/ubuntu-jruby.yml | 4 | ||||
-rw-r--r-- | lib/psych/scalar_scanner.rb | 2 | ||||
-rw-r--r-- | lib/psych/versions.rb | 2 | ||||
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 4 | ||||
-rw-r--r-- | lib/psych/visitors/yaml_tree.rb | 16 | ||||
-rw-r--r-- | test/psych/test_date_time.rb | 20 |
6 files changed, 34 insertions, 14 deletions
diff --git a/.github/workflows/ubuntu-jruby.yml b/.github/workflows/ubuntu-jruby.yml index fd64cf1..f4610a8 100644 --- a/.github/workflows/ubuntu-jruby.yml +++ b/.github/workflows/ubuntu-jruby.yml @@ -16,9 +16,7 @@ jobs: with: ruby-version: ${{ matrix.ruby }} - name: Install dependencies - run: | - gem install bundler --no-document - bundle install + run: gem install ruby-maven power_assert test-unit rake-compiler - name: compile run: rake compile - name: test diff --git a/lib/psych/scalar_scanner.rb b/lib/psych/scalar_scanner.rb index a4f5d8a..2d5d592 100644 --- a/lib/psych/scalar_scanner.rb +++ b/lib/psych/scalar_scanner.rb @@ -57,7 +57,7 @@ module Psych elsif string.match?(/^\d{4}-(?:1[012]|0\d|\d)-(?:[12]\d|3[01]|0\d|\d)$/) require 'date' begin - class_loader.date.strptime(string, '%Y-%m-%d') + class_loader.date.strptime(string, '%F', Date::GREGORIAN) rescue ArgumentError string end diff --git a/lib/psych/versions.rb b/lib/psych/versions.rb index daf5a19..63c0ed6 100644 --- a/lib/psych/versions.rb +++ b/lib/psych/versions.rb @@ -2,7 +2,7 @@ module Psych # The version of Psych you are using - VERSION = '3.3.2' + VERSION = '3.3.3' if RUBY_ENGINE == 'jruby' DEFAULT_SNAKEYAML_VERSION = '1.31'.freeze diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index 4de7f80..37ba034 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -80,7 +80,9 @@ module Psych when "!ruby/object:DateTime" class_loader.date_time require 'date' unless defined? DateTime - @ss.parse_time(o.value).to_datetime + t = @ss.parse_time(o.value) + DateTime.civil(*t.to_a[0, 6].reverse, Rational(t.utc_offset, 86400)) + + (t.subsec/86400) when '!ruby/encoding' ::Encoding.find o.value when "!ruby/object:Complex" diff --git a/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb index bf7c0bb..793e9c2 100644 --- a/lib/psych/visitors/yaml_tree.rb +++ b/lib/psych/visitors/yaml_tree.rb @@ -192,12 +192,13 @@ module Psych register o, @emitter.scalar(o.inspect, nil, '!ruby/regexp', false, false, Nodes::Scalar::ANY) end + def visit_Date o + register o, visit_Integer(o.gregorian) + end + def visit_DateTime o - formatted = if o.offset.zero? - o.strftime("%Y-%m-%d %H:%M:%S.%9N Z".freeze) - else - o.strftime("%Y-%m-%d %H:%M:%S.%9N %:z".freeze) - end + t = o.italy + formatted = format_time t, t.offset.zero? tag = '!ruby/object:DateTime' register o, @emitter.scalar(formatted, nil, tag, false, false, Nodes::Scalar::ANY) end @@ -235,7 +236,6 @@ module Psych end alias :visit_TrueClass :visit_Integer alias :visit_FalseClass :visit_Integer - alias :visit_Date :visit_Integer def visit_Float o if o.nan? @@ -480,8 +480,8 @@ module Psych @emitter.end_mapping end - def format_time time - if time.utc? + def format_time time, utc = time.utc? + if utc time.strftime("%Y-%m-%d %H:%M:%S.%9N Z") else time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z") diff --git a/test/psych/test_date_time.rb b/test/psych/test_date_time.rb index 6f1e8b5..3379bd2 100644 --- a/test/psych/test_date_time.rb +++ b/test/psych/test_date_time.rb @@ -44,6 +44,26 @@ module Psych assert_match(/12:00:00-05:00/, cycled.last.to_s) end + def test_julian_date + d = Date.new(1582, 10, 4, Date::GREGORIAN) + assert_cycle d + end + + def test_proleptic_gregorian_date + d = Date.new(1582, 10, 14, Date::GREGORIAN) + assert_cycle d + end + + def test_julian_datetime + dt = DateTime.new(1582, 10, 4, 23, 58, 59, 0, Date::GREGORIAN) + assert_cycle dt + end + + def test_proleptic_gregorian_datetime + dt = DateTime.new(1582, 10, 14, 23, 58, 59, 0, Date::GREGORIAN) + assert_cycle dt + end + def test_invalid_date assert_cycle "2013-10-31T10:40:07-000000000000033" end |