Skip to content

Bump up v3.3.3 #576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/ubuntu-jruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/psych/scalar_scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def tokenize string
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
Expand Down
2 changes: 1 addition & 1 deletion lib/psych/versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/psych/visitors/to_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def deserialize o
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"
Expand Down
16 changes: 8 additions & 8 deletions lib/psych/visitors/yaml_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,13 @@ def visit_Regexp o
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
Expand Down Expand Up @@ -235,7 +236,6 @@ def visit_Integer o
end
alias :visit_TrueClass :visit_Integer
alias :visit_FalseClass :visit_Integer
alias :visit_Date :visit_Integer

def visit_Float o
if o.nan?
Expand Down Expand Up @@ -480,8 +480,8 @@ def dump_exception o, msg
@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")
Expand Down
20 changes: 20 additions & 0 deletions test/psych/test_date_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ def test_datetime_timezone_offset
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
Expand Down