Skip to content
12 changes: 12 additions & 0 deletions core/time/shared/now.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion library/date/today_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions library/datetime/now_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 32 additions & 1 deletion library/datetime/to_date_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion library/datetime/to_datetime_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 12 additions & 1 deletion library/datetime/to_s_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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