diff --git a/core/time/shared/now.rb b/core/time/shared/now.rb index f570aeedd2..c35115fcf4 100644 --- a/core/time/shared/now.rb +++ b/core/time/shared/now.rb @@ -5,4 +5,16 @@ TimeSpecs::SubTime.send(@method).should be_an_instance_of(TimeSpecs::SubTime) TimeSpecs::MethodHolder.send(@method).should be_an_instance_of(Time) end + + it "sets the current time" do + now = TimeSpecs::MethodHolder.send(@method) + now.to_f.should be_close(Process.clock_gettime(Process::CLOCK_REALTIME), 10.0) + end + + it "uses the local timezone" do + with_timezone("PDT", -8) do + now = TimeSpecs::MethodHolder.send(@method) + now.utc_offset.should == (-8 * 60 * 60) + end + end end diff --git a/library/date/today_spec.rb b/library/date/today_spec.rb index 09e8ed6006..d487be089f 100644 --- a/library/date/today_spec.rb +++ b/library/date/today_spec.rb @@ -2,5 +2,13 @@ require 'date' describe "Date.today" do - it "needs to be reviewed for spec completeness" + it "returns a Date object" do + Date.today.should be_kind_of Date + end + + it "sets Date object to the current date" do + today = Date.today + now = Time.now + (now - today.to_time).should be_close(0.0, 24 * 60 * 60) + end end diff --git a/library/datetime/now_spec.rb b/library/datetime/now_spec.rb index e8c93aa604..a5bf590aff 100644 --- a/library/datetime/now_spec.rb +++ b/library/datetime/now_spec.rb @@ -5,4 +5,21 @@ 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/library/datetime/to_date_spec.rb b/library/datetime/to_date_spec.rb index 915e1ac87a..387eda9229 100644 --- a/library/datetime/to_date_spec.rb +++ b/library/datetime/to_date_spec.rb @@ -2,5 +2,36 @@ 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/library/datetime/to_datetime_spec.rb b/library/datetime/to_datetime_spec.rb index e289f8ce36..e4db9558f1 100644 --- a/library/datetime/to_datetime_spec.rb +++ b/library/datetime/to_datetime_spec.rb @@ -2,5 +2,8 @@ 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/library/datetime/to_s_spec.rb b/library/datetime/to_s_spec.rb index 893cc93283..9d9dfc629f 100644 --- a/library/datetime/to_s_spec.rb +++ b/library/datetime/to_s_spec.rb @@ -2,5 +2,16 @@ 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