summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-08-08 23:26:21 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-08-08 23:48:13 +0900
commit43239b23b48a6c3fde6bdc4b9cc568bedac161b2 (patch)
treed185d49fdf70a672d40975f053b575e635fb16d5 /spec
parente0dfa5967e7063da8b65dc3c062ef4652e246e34 (diff)
[Bug #18946] New tests for fixed Time/DateTime conversions
Diffstat (limited to 'spec')
-rw-r--r--spec/ruby/library/datetime/to_time_spec.rb13
-rw-r--r--spec/ruby/library/time/to_datetime_spec.rb13
2 files changed, 26 insertions, 0 deletions
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
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
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