summaryrefslogtreecommitdiff
path: root/spec/ruby/library/datetime
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/datetime')
-rw-r--r--spec/ruby/library/datetime/_strptime_spec.rb6
-rw-r--r--spec/ruby/library/datetime/civil_spec.rb6
-rw-r--r--spec/ruby/library/datetime/commercial_spec.rb6
-rw-r--r--spec/ruby/library/datetime/hour_spec.rb47
-rw-r--r--spec/ruby/library/datetime/httpdate_spec.rb6
-rw-r--r--spec/ruby/library/datetime/iso8601_spec.rb10
-rw-r--r--spec/ruby/library/datetime/jd_spec.rb6
-rw-r--r--spec/ruby/library/datetime/jisx0301_spec.rb10
-rw-r--r--spec/ruby/library/datetime/min_spec.rb6
-rw-r--r--spec/ruby/library/datetime/minute_spec.rb6
-rw-r--r--spec/ruby/library/datetime/new_offset_spec.rb6
-rw-r--r--spec/ruby/library/datetime/new_spec.rb52
-rw-r--r--spec/ruby/library/datetime/now_spec.rb25
-rw-r--r--spec/ruby/library/datetime/offset_spec.rb6
-rw-r--r--spec/ruby/library/datetime/ordinal_spec.rb6
-rw-r--r--spec/ruby/library/datetime/parse_spec.rb127
-rw-r--r--spec/ruby/library/datetime/rfc2822_spec.rb6
-rw-r--r--spec/ruby/library/datetime/rfc3339_spec.rb10
-rw-r--r--spec/ruby/library/datetime/rfc822_spec.rb6
-rw-r--r--spec/ruby/library/datetime/sec_fraction_spec.rb6
-rw-r--r--spec/ruby/library/datetime/sec_spec.rb6
-rw-r--r--spec/ruby/library/datetime/second_fraction_spec.rb6
-rw-r--r--spec/ruby/library/datetime/second_spec.rb6
-rw-r--r--spec/ruby/library/datetime/shared/min.rb40
-rw-r--r--spec/ruby/library/datetime/shared/sec.rb45
-rw-r--r--spec/ruby/library/datetime/strftime_spec.rb51
-rw-r--r--spec/ruby/library/datetime/strptime_spec.rb6
-rw-r--r--spec/ruby/library/datetime/to_date_spec.rb37
-rw-r--r--spec/ruby/library/datetime/to_datetime_spec.rb9
-rw-r--r--spec/ruby/library/datetime/to_s_spec.rb17
-rw-r--r--spec/ruby/library/datetime/to_time_spec.rb38
-rw-r--r--spec/ruby/library/datetime/xmlschema_spec.rb10
-rw-r--r--spec/ruby/library/datetime/zone_spec.rb6
33 files changed, 636 insertions, 0 deletions
diff --git a/spec/ruby/library/datetime/_strptime_spec.rb b/spec/ruby/library/datetime/_strptime_spec.rb
new file mode 100644
index 0000000000..c8c910618d
--- /dev/null
+++ b/spec/ruby/library/datetime/_strptime_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime._strptime" do
+ it "needs to be reviewed for spec completeness"
+end
diff --git a/spec/ruby/library/datetime/civil_spec.rb b/spec/ruby/library/datetime/civil_spec.rb
new file mode 100644
index 0000000000..77df021e33
--- /dev/null
+++ b/spec/ruby/library/datetime/civil_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime.civil" do
+ it "needs to be reviewed for spec completeness"
+end
diff --git a/spec/ruby/library/datetime/commercial_spec.rb b/spec/ruby/library/datetime/commercial_spec.rb
new file mode 100644
index 0000000000..2984dd5334
--- /dev/null
+++ b/spec/ruby/library/datetime/commercial_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime.commercial" do
+ it "needs to be reviewed for spec completeness"
+end
diff --git a/spec/ruby/library/datetime/hour_spec.rb b/spec/ruby/library/datetime/hour_spec.rb
new file mode 100644
index 0000000000..db89016937
--- /dev/null
+++ b/spec/ruby/library/datetime/hour_spec.rb
@@ -0,0 +1,47 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime#hour" do
+ it "returns 0 if no argument is passed" do
+ DateTime.new.hour.should == 0
+ end
+
+ it "returns the hour given as argument" do
+ new_datetime(hour: 5).hour.should == 5
+ end
+
+ it "adds 24 to negative hours" do
+ new_datetime(hour: -10).hour.should == 14
+ end
+
+ it "raises an error for Rational" do
+ lambda { new_datetime(hour: 1 + Rational(1,2)) }.should raise_error(ArgumentError)
+ end
+
+ it "raises an error for Float" do
+ lambda { new_datetime(hour: 1.5).hour }.should raise_error(ArgumentError)
+ end
+
+ it "raises an error for Rational" do
+ lambda { new_datetime(day: 1 + Rational(1,2)) }.should raise_error(ArgumentError)
+ end
+
+ it "raises an error, when the hour is smaller than -24" do
+ lambda { new_datetime(hour: -25) }.should raise_error(ArgumentError)
+ end
+
+ it "raises an error, when the hour is larger than 24" do
+ lambda { new_datetime(hour: 25) }.should raise_error(ArgumentError)
+ end
+
+ it "raises an error for hour fractions smaller than -24" do
+ lambda { new_datetime(hour: -24 - Rational(1,2)) }.should(
+ raise_error(ArgumentError))
+ end
+
+ it "adds 1 to day, when 24 hours given" do
+ d = new_datetime day: 1, hour: 24
+ d.hour.should == 0
+ d.day.should == 2
+ end
+end
diff --git a/spec/ruby/library/datetime/httpdate_spec.rb b/spec/ruby/library/datetime/httpdate_spec.rb
new file mode 100644
index 0000000000..e97fda7fb4
--- /dev/null
+++ b/spec/ruby/library/datetime/httpdate_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime.httpdate" do
+ it "needs to be reviewed for spec completeness"
+end
diff --git a/spec/ruby/library/datetime/iso8601_spec.rb b/spec/ruby/library/datetime/iso8601_spec.rb
new file mode 100644
index 0000000000..44887148d3
--- /dev/null
+++ b/spec/ruby/library/datetime/iso8601_spec.rb
@@ -0,0 +1,10 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime.iso8601" do
+ it "needs to be reviewed for spec completeness"
+end
+
+describe "DateTime#iso8601" do
+ it "needs to be reviewed for spec completeness"
+end
diff --git a/spec/ruby/library/datetime/jd_spec.rb b/spec/ruby/library/datetime/jd_spec.rb
new file mode 100644
index 0000000000..e8271089f7
--- /dev/null
+++ b/spec/ruby/library/datetime/jd_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime.jd" do
+ it "needs to be reviewed for spec completeness"
+end
diff --git a/spec/ruby/library/datetime/jisx0301_spec.rb b/spec/ruby/library/datetime/jisx0301_spec.rb
new file mode 100644
index 0000000000..2402a21cb0
--- /dev/null
+++ b/spec/ruby/library/datetime/jisx0301_spec.rb
@@ -0,0 +1,10 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime.jisx0301" do
+ it "needs to be reviewed for spec completeness"
+end
+
+describe "DateTime#jisx0301" do
+ it "needs to be reviewed for spec completeness"
+end
diff --git a/spec/ruby/library/datetime/min_spec.rb b/spec/ruby/library/datetime/min_spec.rb
new file mode 100644
index 0000000000..5f7d7e7810
--- /dev/null
+++ b/spec/ruby/library/datetime/min_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/min', __FILE__)
+
+describe "DateTime.min" do
+ it_behaves_like :datetime_min, :min
+end
diff --git a/spec/ruby/library/datetime/minute_spec.rb b/spec/ruby/library/datetime/minute_spec.rb
new file mode 100644
index 0000000000..3ab01572fe
--- /dev/null
+++ b/spec/ruby/library/datetime/minute_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/min', __FILE__)
+
+describe "DateTime.minute" do
+ it_behaves_like :datetime_min, :minute
+end
diff --git a/spec/ruby/library/datetime/new_offset_spec.rb b/spec/ruby/library/datetime/new_offset_spec.rb
new file mode 100644
index 0000000000..b900de6097
--- /dev/null
+++ b/spec/ruby/library/datetime/new_offset_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime#new_offset" do
+ it "needs to be reviewed for spec completeness"
+end
diff --git a/spec/ruby/library/datetime/new_spec.rb b/spec/ruby/library/datetime/new_spec.rb
new file mode 100644
index 0000000000..14ef329d56
--- /dev/null
+++ b/spec/ruby/library/datetime/new_spec.rb
@@ -0,0 +1,52 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime.new" do
+ it "sets all values to default if passed no arguments" do
+ d = DateTime.new
+ d.year.should == -4712
+ d.month.should == 1
+ d.day.should == 1
+ d.hour.should == 0
+ d.min.should == 0
+ d.sec.should == 0
+ d.sec_fraction.should == 0
+ d.offset.should == 0
+ end
+
+ it "takes the first argument as year" do
+ DateTime.new(2011).year.should == 2011
+ end
+
+ it "takes the second argument as month" do
+ DateTime.new(2011, 2).month.should == 2
+ end
+
+ it "takes the third argument as day" do
+ DateTime.new(2011, 2, 3).day.should == 3
+ end
+
+ it "takes the forth argument as hour" do
+ DateTime.new(2011, 2, 3, 4).hour.should == 4
+ end
+
+ it "takes the fifth argument as minute" do
+ DateTime.new(1, 2, 3, 4, 5).min.should == 5
+ end
+
+ it "takes the sixth argument as second" do
+ DateTime.new(1, 2, 3, 4, 5, 6).sec.should == 6
+ end
+
+ it "takes the seventh argument as an offset" do
+ DateTime.new(1, 2, 3, 4, 5, 6, 0.7).offset.should == 0.7
+ end
+
+ 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
+
+ it "raises an error on invalid arguments" do
+ lambda { new_datetime(minute: 999) }.should raise_error(ArgumentError)
+ end
+end
diff --git a/spec/ruby/library/datetime/now_spec.rb b/spec/ruby/library/datetime/now_spec.rb
new file mode 100644
index 0000000000..9118163533
--- /dev/null
+++ b/spec/ruby/library/datetime/now_spec.rb
@@ -0,0 +1,25 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+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, 2.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/offset_spec.rb b/spec/ruby/library/datetime/offset_spec.rb
new file mode 100644
index 0000000000..c11d28bad2
--- /dev/null
+++ b/spec/ruby/library/datetime/offset_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime#offset" do
+ it "needs to be reviewed for spec completeness"
+end
diff --git a/spec/ruby/library/datetime/ordinal_spec.rb b/spec/ruby/library/datetime/ordinal_spec.rb
new file mode 100644
index 0000000000..2ada512e05
--- /dev/null
+++ b/spec/ruby/library/datetime/ordinal_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime.ordinal" do
+ it "needs to be reviewed for spec completeness"
+end
diff --git a/spec/ruby/library/datetime/parse_spec.rb b/spec/ruby/library/datetime/parse_spec.rb
new file mode 100644
index 0000000000..14a68f1499
--- /dev/null
+++ b/spec/ruby/library/datetime/parse_spec.rb
@@ -0,0 +1,127 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime.parse" do
+
+ it "parses a day name into a DateTime object" do
+ d = DateTime.parse("friday")
+ d.should == DateTime.commercial(d.cwyear, d.cweek, 5)
+ end
+
+ it "parses a month name into a DateTime object" do
+ d = DateTime.parse("october")
+ d.should == DateTime.civil(Date.today.year, 10)
+ end
+
+ it "parses a month day into a DateTime object" do
+ d = DateTime.parse("5th")
+ d.should == DateTime.civil(Date.today.year, Date.today.month, 5)
+ end
+
+ # Specs using numbers
+ it "throws an argument error for a single digit" do
+ lambda{ DateTime.parse("1") }.should raise_error(ArgumentError)
+ end
+
+ it "parses DD as month day number" do
+ d = DateTime.parse("10")
+ d.should == DateTime.civil(Date.today.year, Date.today.month, 10)
+ end
+
+ it "parses DDD as year day number" do
+ d = DateTime.parse("100")
+ if DateTime.gregorian_leap?(Date.today.year)
+ d.should == DateTime.civil(Date.today.year, 4, 9)
+ else
+ d.should == DateTime.civil(Date.today.year, 4, 10)
+ end
+ end
+
+ it "parses MMDD as month and day" do
+ d = DateTime.parse("1108")
+ d.should == DateTime.civil(Date.today.year, 11, 8)
+ end
+
+ it "parses YYYYMMDD as year, month and day" do
+ d = DateTime.parse("20121108")
+ d.should == DateTime.civil(2012, 11, 8)
+ end
+
+ describe "YYYY-MM-DDTHH:MM:SS format" do
+ it "parses YYYY-MM-DDTHH:MM:SS into a DateTime object" do
+ d = DateTime.parse("2012-11-08T15:43:59")
+ d.should == DateTime.civil(2012, 11, 8, 15, 43, 59)
+ end
+
+ it "throws an argument error for invalid month values" do
+ lambda{DateTime.parse("2012-13-08T15:43:59")}.should raise_error(ArgumentError)
+ end
+
+ it "throws an argument error for invalid day values" do
+ lambda{DateTime.parse("2012-12-32T15:43:59")}.should raise_error(ArgumentError)
+ end
+
+ it "throws an argument error for invalid hour values" do
+ lambda{DateTime.parse("2012-12-31T25:43:59")}.should raise_error(ArgumentError)
+ end
+
+ it "throws an argument error for invalid minute values" do
+ lambda{DateTime.parse("2012-12-31T25:43:59")}.should raise_error(ArgumentError)
+ end
+
+ it "throws an argument error for invalid second values" do
+ lambda{DateTime.parse("2012-11-08T15:43:61")}.should raise_error(ArgumentError)
+ end
+
+ end
+
+ it "parses YYDDD as year and day number in 1969--2068" do
+ d = DateTime.parse("10100")
+ d.should == DateTime.civil(2010, 4, 10)
+ end
+
+ it "parses YYMMDD as year, month and day in 1969--2068" do
+ d = DateTime.parse("201023")
+ d.should == DateTime.civil(2020, 10, 23)
+ end
+
+ it "parses YYYYDDD as year and day number" do
+ d = DateTime.parse("1910100")
+ d.should == DateTime.civil(1910, 4, 10)
+ end
+
+ it "parses YYYYMMDD as year, month and day number" do
+ d = DateTime.parse("19101101")
+ d.should == DateTime.civil(1910, 11, 1)
+ end
+end
+
+describe "DateTime.parse(.)" do
+ it "parses YYYY.MM.DD into a DateTime object" do
+ d = DateTime.parse("2007.10.01")
+ d.year.should == 2007
+ d.month.should == 10
+ d.day.should == 1
+ end
+
+ it "parses DD.MM.YYYY into a DateTime object" do
+ d = DateTime.parse("10.01.2007")
+ d.year.should == 2007
+ d.month.should == 1
+ d.day.should == 10
+ end
+
+ it "parses YY.MM.DD into a DateTime object using the year 20YY" do
+ d = DateTime.parse("10.01.07")
+ d.year.should == 2010
+ d.month.should == 1
+ d.day.should == 7
+ end
+
+ it "parses YY.MM.DD using the year digits as 20YY when given true as additional argument" do
+ d = DateTime.parse("10.01.07", true)
+ d.year.should == 2010
+ d.month.should == 1
+ d.day.should == 7
+ end
+end
diff --git a/spec/ruby/library/datetime/rfc2822_spec.rb b/spec/ruby/library/datetime/rfc2822_spec.rb
new file mode 100644
index 0000000000..3fc4dc14b8
--- /dev/null
+++ b/spec/ruby/library/datetime/rfc2822_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime.rfc2822" do
+ it "needs to be reviewed for spec completeness"
+end
diff --git a/spec/ruby/library/datetime/rfc3339_spec.rb b/spec/ruby/library/datetime/rfc3339_spec.rb
new file mode 100644
index 0000000000..4fea795d9e
--- /dev/null
+++ b/spec/ruby/library/datetime/rfc3339_spec.rb
@@ -0,0 +1,10 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime.rfc3339" do
+ it "needs to be reviewed for spec completeness"
+end
+
+describe "DateTime#rfc3339" do
+ it "needs to be reviewed for spec completeness"
+end
diff --git a/spec/ruby/library/datetime/rfc822_spec.rb b/spec/ruby/library/datetime/rfc822_spec.rb
new file mode 100644
index 0000000000..f86ee77379
--- /dev/null
+++ b/spec/ruby/library/datetime/rfc822_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime.rfc822" do
+ it "needs to be reviewed for spec completeness"
+end
diff --git a/spec/ruby/library/datetime/sec_fraction_spec.rb b/spec/ruby/library/datetime/sec_fraction_spec.rb
new file mode 100644
index 0000000000..3ed274a5bc
--- /dev/null
+++ b/spec/ruby/library/datetime/sec_fraction_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime#sec_fraction" do
+ it "needs to be reviewed for spec completeness"
+end
diff --git a/spec/ruby/library/datetime/sec_spec.rb b/spec/ruby/library/datetime/sec_spec.rb
new file mode 100644
index 0000000000..c7e9af2650
--- /dev/null
+++ b/spec/ruby/library/datetime/sec_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/sec', __FILE__)
+
+describe "DateTime.sec" do
+ it_behaves_like :datetime_sec, :sec
+end
diff --git a/spec/ruby/library/datetime/second_fraction_spec.rb b/spec/ruby/library/datetime/second_fraction_spec.rb
new file mode 100644
index 0000000000..32dc9333f6
--- /dev/null
+++ b/spec/ruby/library/datetime/second_fraction_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime#second_fraction" do
+ it "needs to be reviewed for spec completeness"
+end
diff --git a/spec/ruby/library/datetime/second_spec.rb b/spec/ruby/library/datetime/second_spec.rb
new file mode 100644
index 0000000000..08cdf463f7
--- /dev/null
+++ b/spec/ruby/library/datetime/second_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../shared/sec', __FILE__)
+
+describe "DateTime#second" do
+ it_behaves_like :datetime_sec, :second
+end
diff --git a/spec/ruby/library/datetime/shared/min.rb b/spec/ruby/library/datetime/shared/min.rb
new file mode 100644
index 0000000000..e69d86ab02
--- /dev/null
+++ b/spec/ruby/library/datetime/shared/min.rb
@@ -0,0 +1,40 @@
+require 'date'
+
+describe :datetime_min, shared: true do
+ it "returns 0 if no argument is passed" do
+ DateTime.new.send(@method).should == 0
+ end
+
+ it "returns the minute passed as argument" do
+ new_datetime(minute: 5).send(@method).should == 5
+ end
+
+ it "adds 60 to negative minutes" do
+ new_datetime(minute: -20).send(@method).should == 40
+ end
+
+ it "raises an error for Rational" do
+ lambda { new_datetime minute: 5 + Rational(1,2) }.should raise_error(ArgumentError)
+ end
+
+ it "raises an error for Float" do
+ lambda { new_datetime minute: 5.5 }.should raise_error(ArgumentError)
+ end
+
+ it "raises an error for Rational" do
+ lambda { new_datetime(hour: 2 + Rational(1,2)) }.should raise_error(ArgumentError)
+ end
+
+ it "raises an error, when the minute is smaller than -60" do
+ lambda { new_datetime(minute: -61) }.should raise_error(ArgumentError)
+ end
+
+ it "raises an error, when the minute is greater or equal than 60" do
+ lambda { new_datetime(minute: 60) }.should raise_error(ArgumentError)
+ end
+
+ it "raises an error for minute fractions smaller than -60" do
+ lambda { new_datetime(minute: -60 - Rational(1,2))}.should(
+ raise_error(ArgumentError))
+ end
+end
diff --git a/spec/ruby/library/datetime/shared/sec.rb b/spec/ruby/library/datetime/shared/sec.rb
new file mode 100644
index 0000000000..68e8af8e40
--- /dev/null
+++ b/spec/ruby/library/datetime/shared/sec.rb
@@ -0,0 +1,45 @@
+require 'date'
+
+describe :datetime_sec, shared: true do
+ it "returns 0 seconds if passed no arguments" do
+ d = DateTime.new
+ d.send(@method).should == 0
+ end
+
+ it "returns the seconds passed in the arguments" do
+ new_datetime(second: 5).send(@method).should == 5
+ end
+
+ it "adds 60 to negative values" do
+ new_datetime(second: -20).send(@method).should == 40
+ end
+
+ it "returns the absolute value of a Rational" do
+ new_datetime(second: 5 + Rational(1,2)).send(@method).should == 5
+ end
+
+ it "returns the absolute value of a float" do
+ new_datetime(second: 5.5).send(@method).should == 5
+ end
+
+ it "raises an error when minute is given as a rational" do
+ lambda { new_datetime(minute: 5 + Rational(1,2)) }.should raise_error(ArgumentError)
+ end
+
+ it "raises an error, when the second is smaller than -60" do
+ lambda { new_datetime(second: -61) }.should raise_error(ArgumentError)
+ end
+
+ it "raises an error, when the second is greater or equal than 60" do
+ lambda { new_datetime(second: 60) }.should raise_error(ArgumentError)
+ end
+
+ it "raises an error for second fractions smaller than -60" do
+ lambda { new_datetime(second: -60 - Rational(1,2))}.should(
+ raise_error(ArgumentError))
+ end
+
+ it "takes a second fraction near 60" do
+ new_datetime(second: 59 + Rational(1,2)).send(@method).should == 59
+ end
+end
diff --git a/spec/ruby/library/datetime/strftime_spec.rb b/spec/ruby/library/datetime/strftime_spec.rb
new file mode 100644
index 0000000000..37705788a1
--- /dev/null
+++ b/spec/ruby/library/datetime/strftime_spec.rb
@@ -0,0 +1,51 @@
+require 'date'
+require File.expand_path('../../../shared/time/strftime_for_date', __FILE__)
+require File.expand_path('../../../shared/time/strftime_for_time', __FILE__)
+
+describe "DateTime#strftime" do
+ before :all do
+ @new_date = lambda { |y,m,d| DateTime.civil(y,m,d) }
+ @new_time = lambda { |*args| DateTime.civil(*args) }
+ @new_time_in_zone = lambda { |zone,offset,*args|
+ y, m, d, h, min, s = args
+ DateTime.new(y, m||1, d||1, h||0, min||0, s||0, Rational(offset, 24))
+ }
+ @new_time_with_offset = lambda { |y,m,d,h,min,s,offset|
+ DateTime.new(y,m,d,h,min,s, Rational(offset, 86_400))
+ }
+
+ @time = DateTime.civil(2001, 2, 3, 4, 5, 6)
+ end
+
+ it_behaves_like :strftime_date, :strftime
+ it_behaves_like :strftime_time, :strftime
+
+ # Differences with Time
+ it "should be able to print the datetime with no argument" do
+ @time.strftime.should == "2001-02-03T04:05:06+00:00"
+ @time.strftime.should == @time.to_s
+ end
+
+ # %Z is %:z for Date/DateTime
+ it "should be able to show the timezone with a : separator" do
+ @time.strftime("%Z").should == "+00:00"
+ end
+
+ # %v is %e-%b-%Y for Date/DateTime
+ it "should be able to show the commercial week" do
+ @time.strftime("%v").should == " 3-Feb-2001"
+ @time.strftime("%v").should == @time.strftime('%e-%b-%Y')
+ end
+
+ # additional conversion specifiers only in Date/DateTime
+ it 'shows the number of milliseconds since epoch' do
+ DateTime.new(1970, 1, 1, 0, 0, 0).strftime("%Q").should == "0"
+ @time.strftime("%Q").should == "981173106000"
+ DateTime.civil(2001, 2, 3, 4, 5, Rational(6123, 1000)).strftime("%Q").should == "981173106123"
+ end
+
+ it "should be able to show a full notation" do
+ @time.strftime("%+").should == "Sat Feb 3 04:05:06 +00:00 2001"
+ @time.strftime("%+").should == @time.strftime('%a %b %e %H:%M:%S %Z %Y')
+ end
+end
diff --git a/spec/ruby/library/datetime/strptime_spec.rb b/spec/ruby/library/datetime/strptime_spec.rb
new file mode 100644
index 0000000000..f3098f6f6b
--- /dev/null
+++ b/spec/ruby/library/datetime/strptime_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime.strptime" do
+ it "needs to be reviewed for spec completeness"
+end
diff --git a/spec/ruby/library/datetime/to_date_spec.rb b/spec/ruby/library/datetime/to_date_spec.rb
new file mode 100644
index 0000000000..387eda9229
--- /dev/null
+++ b/spec/ruby/library/datetime/to_date_spec.rb
@@ -0,0 +1,37 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime#to_date" do
+ 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
new file mode 100644
index 0000000000..e4db9558f1
--- /dev/null
+++ b/spec/ruby/library/datetime/to_datetime_spec.rb
@@ -0,0 +1,9 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime#to_datetime" do
+ 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
new file mode 100644
index 0000000000..9d9dfc629f
--- /dev/null
+++ b/spec/ruby/library/datetime/to_s_spec.rb
@@ -0,0 +1,17 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime#to_s" do
+ 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
new file mode 100644
index 0000000000..2a016d1528
--- /dev/null
+++ b/spec/ruby/library/datetime/to_time_spec.rb
@@ -0,0 +1,38 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime#to_time" do
+ it "yields a new Time object" do
+ DateTime.now.to_time.should be_kind_of(Time)
+ end
+
+ it "returns a Time representing the same instant" do
+ datetime = DateTime.civil(3, 12, 31, 23, 58, 59)
+ time = datetime.to_time.utc
+
+ time.year.should == 3
+ time.month.should == 12
+ time.day.should == 31
+ time.hour.should == 23
+ time.min.should == 58
+ time.sec.should == 59
+ 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
diff --git a/spec/ruby/library/datetime/xmlschema_spec.rb b/spec/ruby/library/datetime/xmlschema_spec.rb
new file mode 100644
index 0000000000..5f33d33436
--- /dev/null
+++ b/spec/ruby/library/datetime/xmlschema_spec.rb
@@ -0,0 +1,10 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime.xmlschema" do
+ it "needs to be reviewed for spec completeness"
+end
+
+describe "DateTime#xmlschema" do
+ it "needs to be reviewed for spec completeness"
+end
diff --git a/spec/ruby/library/datetime/zone_spec.rb b/spec/ruby/library/datetime/zone_spec.rb
new file mode 100644
index 0000000000..fa8c9a982d
--- /dev/null
+++ b/spec/ruby/library/datetime/zone_spec.rb
@@ -0,0 +1,6 @@
+require File.expand_path('../../../spec_helper', __FILE__)
+require 'date'
+
+describe "DateTime#zone" do
+ it "needs to be reviewed for spec completeness"
+end