summaryrefslogtreecommitdiff
path: root/spec/ruby/library/datetime
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-28 15:15:48 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-28 15:15:48 +0000
commit8c5b60eb22d6d661e87992a65d54e3a5bc0aeed4 (patch)
tree7905b284cb5b3d62c17ad8a939e339621a498a2c /spec/ruby/library/datetime
parent6530b14cee76e2512424d225e64d3c61dd1f6511 (diff)
Update to ruby/spec@a6b8805
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/library/datetime')
-rw-r--r--spec/ruby/library/datetime/new_spec.rb2
-rw-r--r--spec/ruby/library/datetime/now_spec.rb17
-rw-r--r--spec/ruby/library/datetime/to_date_spec.rb33
-rw-r--r--spec/ruby/library/datetime/to_datetime_spec.rb5
-rw-r--r--spec/ruby/library/datetime/to_s_spec.rb13
-rw-r--r--spec/ruby/library/datetime/to_time_spec.rb22
6 files changed, 87 insertions, 5 deletions
diff --git a/spec/ruby/library/datetime/new_spec.rb b/spec/ruby/library/datetime/new_spec.rb
index a8275a1..14ef329 100644
--- a/spec/ruby/library/datetime/new_spec.rb
+++ b/spec/ruby/library/datetime/new_spec.rb
@@ -42,7 +42,7 @@ describe "DateTime.new" do
DateTime.new(1, 2, 3, 4, 5, 6, 0.7).offset.should == 0.7
end
- it "takes the eigth argument as the date of calendar reform" do
+ it "takes the eighth argument as the date of calendar reform" do
DateTime.new(1, 2, 3, 4, 5, 6, 0.7, Date::ITALY).start().should == Date::ITALY
end
diff --git a/spec/ruby/library/datetime/now_spec.rb b/spec/ruby/library/datetime/now_spec.rb
index e8c93aa..a5bf590 100644
--- a/spec/ruby/library/datetime/now_spec.rb
+++ b/spec/ruby/library/datetime/now_spec.rb
@@ -5,4 +5,21 @@ describe "DateTime.now" do
it "creates an instance of DateTime" do
DateTime.now.should be_an_instance_of(DateTime)
end
+
+ it "sets the current date" do
+ (DateTime.now - Date.today).to_f.should be_close(0.0, 1.0)
+ end
+
+ it "sets the current time" do
+ dt = DateTime.now
+ now = Time.now
+ (dt.to_time - now).should be_close(0.0, 10.0)
+ end
+
+ it "grabs the local timezone" do
+ with_timezone("PDT", -8) do
+ dt = DateTime.now
+ dt.zone.should == "-08:00"
+ end
+ end
end
diff --git a/spec/ruby/library/datetime/to_date_spec.rb b/spec/ruby/library/datetime/to_date_spec.rb
index 915e1ac..387eda9 100644
--- a/spec/ruby/library/datetime/to_date_spec.rb
+++ b/spec/ruby/library/datetime/to_date_spec.rb
@@ -2,5 +2,36 @@ require File.expand_path('../../../spec_helper', __FILE__)
require 'date'
describe "DateTime#to_date" do
- it "needs to be reviewed for spec completeness"
+ it "returns an instance of Date" do
+ dt = DateTime.new(2012, 12, 24, 12, 23, 00, '+05:00')
+ dt.to_date.should be_kind_of(Date)
+ end
+
+ it "maintains the same year" do
+ dt = DateTime.new(2012, 12, 24, 12, 23, 00, '+05:00')
+ dt.to_date.year.should == dt.year
+ end
+
+ it "maintains the same month" do
+ dt = DateTime.new(2012, 12, 24, 12, 23, 00, '+05:00')
+ dt.to_date.mon.should == dt.mon
+ end
+
+ it "maintains the same day" do
+ dt = DateTime.new(2012, 12, 24, 12, 23, 00, '+05:00')
+ dt.to_date.day.should == dt.day
+ end
+
+ it "maintains the same mday" do
+ dt = DateTime.new(2012, 12, 24, 12, 23, 00, '+05:00')
+ dt.to_date.mday.should == dt.mday
+ end
+
+ it "maintains the same julian day regardless of local time or zone" do
+ dt = DateTime.new(2012, 12, 24, 12, 23, 00, '+05:00')
+
+ with_timezone("Pactific/Pago_Pago", -11) do
+ dt.to_date.jd.should == dt.jd
+ end
+ end
end
diff --git a/spec/ruby/library/datetime/to_datetime_spec.rb b/spec/ruby/library/datetime/to_datetime_spec.rb
index e289f8c..e4db955 100644
--- a/spec/ruby/library/datetime/to_datetime_spec.rb
+++ b/spec/ruby/library/datetime/to_datetime_spec.rb
@@ -2,5 +2,8 @@ require File.expand_path('../../../spec_helper', __FILE__)
require 'date'
describe "DateTime#to_datetime" do
- it "needs to be reviewed for spec completeness"
+ it "returns itself" do
+ dt = DateTime.new(2012, 12, 24, 12, 23, 00, '+05:00')
+ dt.to_datetime.should == dt
+ end
end
diff --git a/spec/ruby/library/datetime/to_s_spec.rb b/spec/ruby/library/datetime/to_s_spec.rb
index 893cc93..9d9dfc6 100644
--- a/spec/ruby/library/datetime/to_s_spec.rb
+++ b/spec/ruby/library/datetime/to_s_spec.rb
@@ -2,5 +2,16 @@ require File.expand_path('../../../spec_helper', __FILE__)
require 'date'
describe "DateTime#to_s" do
- it "needs to be reviewed for spec completeness"
+ it "returns a new String object" do
+ dt = DateTime.new(2012, 12, 24, 1, 2, 3, "+03:00")
+ dt.to_s.should be_kind_of(String)
+ end
+
+ it "maintains timezone regardless of local time" do
+ dt = DateTime.new(2012, 12, 24, 1, 2, 3, "+03:00")
+
+ with_timezone("Pactific/Pago_Pago", -11) do
+ dt.to_s.should == "2012-12-24T01:02:03+03:00"
+ end
+ end
end
diff --git a/spec/ruby/library/datetime/to_time_spec.rb b/spec/ruby/library/datetime/to_time_spec.rb
index aa29029..f5b7cb8 100644
--- a/spec/ruby/library/datetime/to_time_spec.rb
+++ b/spec/ruby/library/datetime/to_time_spec.rb
@@ -2,5 +2,25 @@ require File.expand_path('../../../spec_helper', __FILE__)
require 'date'
describe "DateTime#to_time" do
- it "needs to be reviewed for spec completeness"
+ it "yields a new Time object" do
+ DateTime.now.to_time.should be_kind_of(Time)
+ end
+
+ ruby_version_is "2.4" do
+ it "preserves the same time regardless of local time or zone" do
+ date = DateTime.new(2012, 12, 24, 12, 23, 00, '+03:00')
+
+ with_timezone("Pactific/Pago_Pago", -11) do
+ time = date.to_time
+
+ time.utc_offset.should == 3 * 3600
+ time.year.should == date.year
+ time.mon.should == date.mon
+ time.day.should == date.day
+ time.hour.should == date.hour
+ time.min.should == date.min
+ time.sec.should == date.sec
+ end
+ end
+ end
end