ruby-changes:72859
From: Nobuyoshi <ko1@a...>
Date: Mon, 8 Aug 2022 23:49:44 +0900 (JST)
Subject: [ruby-changes:72859] 43239b23b4 (master): [Bug #18946] New tests for fixed Time/DateTime conversions
https://git.ruby-lang.org/ruby.git/commit/?id=43239b23b4 From 43239b23b48a6c3fde6bdc4b9cc568bedac161b2 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Mon, 8 Aug 2022 23:26:21 +0900 Subject: [Bug #18946] New tests for fixed Time/DateTime conversions --- spec/ruby/library/datetime/to_time_spec.rb | 13 +++++++++++++ spec/ruby/library/time/to_datetime_spec.rb | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/spec/ruby/library/datetime/to_time_spec.rb b/spec/ruby/library/datetime/to_time_spec.rb index a03ab67867..88a7aaa739 100644 --- a/spec/ruby/library/datetime/to_time_spec.rb +++ b/spec/ruby/library/datetime/to_time_spec.rb @@ -18,6 +18,19 @@ describe "DateTime#to_time" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/datetime/to_time_spec.rb#L18 time.sec.should == 59 end + version_is(Date::VERSION, '3.2.3') do + it "returns a Time representing the same instant before Gregorian" do + datetime = DateTime.civil(1582, 10, 4, 23, 58, 59) + time = datetime.to_time.utc + time.year.should == 1582 + time.month.should == 10 + time.day.should == 14 + time.hour.should == 23 + time.min.should == 58 + time.sec.should == 59 + end + end + it "preserves the same time regardless of local time or zone" do date = DateTime.new(2012, 12, 24, 12, 23, 00, '+03:00') diff --git a/spec/ruby/library/time/to_datetime_spec.rb b/spec/ruby/library/time/to_datetime_spec.rb index 2c1e060f0f..c5561535b2 100644 --- a/spec/ruby/library/time/to_datetime_spec.rb +++ b/spec/ruby/library/time/to_datetime_spec.rb @@ -13,6 +13,19 @@ describe "Time#to_datetime" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/time/to_datetime_spec.rb#L13 datetime.sec.should == 59 end + version_is(Date::VERSION, '3.2.3') do + it "returns a DateTime representing the same instant before Gregorian" do + time = Time.utc(1582, 10, 14, 23, 58, 59) + datetime = time.to_datetime + datetime.year.should == 1582 + datetime.month.should == 10 + datetime.day.should == 4 + datetime.hour.should == 23 + datetime.min.should == 58 + datetime.sec.should == 59 + end + end + it "roundtrips" do time = Time.utc(3, 12, 31, 23, 58, 59) datetime = time.to_datetime -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/