summaryrefslogtreecommitdiff
path: root/spec/ruby/library/time
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/time')
-rw-r--r--spec/ruby/library/time/iso8601_spec.rb7
-rw-r--r--spec/ruby/library/time/rfc2822_spec.rb65
-rw-r--r--spec/ruby/library/time/rfc822_spec.rb5
-rw-r--r--spec/ruby/library/time/shared/rfc2822.rb65
-rw-r--r--spec/ruby/library/time/shared/xmlschema.rb53
-rw-r--r--spec/ruby/library/time/to_date_spec.rb42
-rw-r--r--spec/ruby/library/time/to_datetime_spec.rb40
-rw-r--r--spec/ruby/library/time/to_time_spec.rb4
-rw-r--r--spec/ruby/library/time/xmlschema_spec.rb53
9 files changed, 123 insertions, 211 deletions
diff --git a/spec/ruby/library/time/iso8601_spec.rb b/spec/ruby/library/time/iso8601_spec.rb
index 4a9eb45613..d78de76792 100644
--- a/spec/ruby/library/time/iso8601_spec.rb
+++ b/spec/ruby/library/time/iso8601_spec.rb
@@ -1,7 +1,8 @@
require_relative '../../spec_helper'
-require_relative 'shared/xmlschema'
require 'time'
-describe "Time.xmlschema" do
- it_behaves_like :time_xmlschema, :iso8601
+describe "Time.iso8601" do
+ it "is an alias of Time.xmlschema" do
+ Time.method(:iso8601).should == Time.method(:xmlschema)
+ end
end
diff --git a/spec/ruby/library/time/rfc2822_spec.rb b/spec/ruby/library/time/rfc2822_spec.rb
index 7fc5e9a64b..14824e2396 100644
--- a/spec/ruby/library/time/rfc2822_spec.rb
+++ b/spec/ruby/library/time/rfc2822_spec.rb
@@ -1,7 +1,68 @@
require_relative '../../spec_helper'
-require_relative 'shared/rfc2822'
require 'time'
describe "Time.rfc2822" do
- it_behaves_like :time_rfc2822, :rfc2822
+ it "parses RFC-822 strings" do
+ t1 = (Time.utc(1976, 8, 26, 14, 30) + 4 * 3600)
+ t2 = Time.rfc2822("26 Aug 76 14:30 EDT")
+ t1.should == t2
+
+ t3 = Time.utc(1976, 8, 27, 9, 32) + 7 * 3600
+ t4 = Time.rfc2822("27 Aug 76 09:32 PDT")
+ t3.should == t4
+ end
+
+ it "parses RFC-2822 strings" do
+ t1 = Time.utc(1997, 11, 21, 9, 55, 6) + 6 * 3600
+ t2 = Time.rfc2822("Fri, 21 Nov 1997 09:55:06 -0600")
+ t1.should == t2
+
+ t3 = Time.utc(2003, 7, 1, 10, 52, 37) - 2 * 3600
+ t4 = Time.rfc2822("Tue, 1 Jul 2003 10:52:37 +0200")
+ t3.should == t4
+
+ t5 = Time.utc(1997, 11, 21, 10, 1, 10) + 6 * 3600
+ t6 = Time.rfc2822("Fri, 21 Nov 1997 10:01:10 -0600")
+ t5.should == t6
+
+ t7 = Time.utc(1997, 11, 21, 11, 0, 0) + 6 * 3600
+ t8 = Time.rfc2822("Fri, 21 Nov 1997 11:00:00 -0600")
+ t7.should == t8
+
+ t9 = Time.utc(1997, 11, 24, 14, 22, 1) + 8 * 3600
+ t10 = Time.rfc2822("Mon, 24 Nov 1997 14:22:01 -0800")
+ t9.should == t10
+
+ begin
+ Time.at(-1)
+ rescue ArgumentError
+ # ignore
+ else
+ t11 = Time.utc(1969, 2, 13, 23, 32, 54) + 3 * 3600 + 30 * 60
+ t12 = Time.rfc2822("Thu, 13 Feb 1969 23:32:54 -0330")
+ t11.should == t12
+
+ t13 = Time.utc(1969, 2, 13, 23, 32, 0) + 3 * 3600 + 30 * 60
+ t14 = Time.rfc2822(" Thu,
+ 13
+ Feb
+ 1969
+ 23:32
+ -0330 (Newfoundland Time)")
+ t13.should == t14
+ end
+
+ t15 = Time.utc(1997, 11, 21, 9, 55, 6)
+ t16 = Time.rfc2822("21 Nov 97 09:55:06 GMT")
+ t15.should == t16
+
+ t17 = Time.utc(1997, 11, 21, 9, 55, 6) + 6 * 3600
+ t18 = Time.rfc2822("Fri, 21 Nov 1997 09 : 55 : 06 -0600")
+ t17.should == t18
+
+ -> {
+ # inner comment is not supported.
+ Time.rfc2822("Fri, 21 Nov 1997 09(comment): 55 : 06 -0600")
+ }.should.raise(ArgumentError)
+ end
end
diff --git a/spec/ruby/library/time/rfc822_spec.rb b/spec/ruby/library/time/rfc822_spec.rb
index da77e6ee77..e32e9becae 100644
--- a/spec/ruby/library/time/rfc822_spec.rb
+++ b/spec/ruby/library/time/rfc822_spec.rb
@@ -1,7 +1,8 @@
require_relative '../../spec_helper'
-require_relative 'shared/rfc2822'
require 'time'
describe "Time.rfc822" do
- it_behaves_like :time_rfc2822, :rfc822
+ it "is an alias of Time.rfc2822" do
+ Time.method(:rfc822).should == Time.method(:rfc2822)
+ end
end
diff --git a/spec/ruby/library/time/shared/rfc2822.rb b/spec/ruby/library/time/shared/rfc2822.rb
deleted file mode 100644
index d99f1f76de..0000000000
--- a/spec/ruby/library/time/shared/rfc2822.rb
+++ /dev/null
@@ -1,65 +0,0 @@
-describe :time_rfc2822, shared: true do
- it "parses RFC-822 strings" do
- t1 = (Time.utc(1976, 8, 26, 14, 30) + 4 * 3600)
- t2 = Time.rfc2822("26 Aug 76 14:30 EDT")
- t1.should == t2
-
- t3 = Time.utc(1976, 8, 27, 9, 32) + 7 * 3600
- t4 = Time.rfc2822("27 Aug 76 09:32 PDT")
- t3.should == t4
- end
-
- it "parses RFC-2822 strings" do
- t1 = Time.utc(1997, 11, 21, 9, 55, 6) + 6 * 3600
- t2 = Time.rfc2822("Fri, 21 Nov 1997 09:55:06 -0600")
- t1.should == t2
-
- t3 = Time.utc(2003, 7, 1, 10, 52, 37) - 2 * 3600
- t4 = Time.rfc2822("Tue, 1 Jul 2003 10:52:37 +0200")
- t3.should == t4
-
- t5 = Time.utc(1997, 11, 21, 10, 1, 10) + 6 * 3600
- t6 = Time.rfc2822("Fri, 21 Nov 1997 10:01:10 -0600")
- t5.should == t6
-
- t7 = Time.utc(1997, 11, 21, 11, 0, 0) + 6 * 3600
- t8 = Time.rfc2822("Fri, 21 Nov 1997 11:00:00 -0600")
- t7.should == t8
-
- t9 = Time.utc(1997, 11, 24, 14, 22, 1) + 8 * 3600
- t10 = Time.rfc2822("Mon, 24 Nov 1997 14:22:01 -0800")
- t9.should == t10
-
- begin
- Time.at(-1)
- rescue ArgumentError
- # ignore
- else
- t11 = Time.utc(1969, 2, 13, 23, 32, 54) + 3 * 3600 + 30 * 60
- t12 = Time.rfc2822("Thu, 13 Feb 1969 23:32:54 -0330")
- t11.should == t12
-
- t13 = Time.utc(1969, 2, 13, 23, 32, 0) + 3 * 3600 + 30 * 60
- t14 = Time.rfc2822(" Thu,
- 13
- Feb
- 1969
- 23:32
- -0330 (Newfoundland Time)")
- t13.should == t14
- end
-
- t15 = Time.utc(1997, 11, 21, 9, 55, 6)
- t16 = Time.rfc2822("21 Nov 97 09:55:06 GMT")
- t15.should == t16
-
- t17 = Time.utc(1997, 11, 21, 9, 55, 6) + 6 * 3600
- t18 = Time.rfc2822("Fri, 21 Nov 1997 09 : 55 : 06 -0600")
- t17.should == t18
-
- -> {
- # inner comment is not supported.
- Time.rfc2822("Fri, 21 Nov 1997 09(comment): 55 : 06 -0600")
- }.should raise_error(ArgumentError)
- end
-end
diff --git a/spec/ruby/library/time/shared/xmlschema.rb b/spec/ruby/library/time/shared/xmlschema.rb
deleted file mode 100644
index 44d33cda7e..0000000000
--- a/spec/ruby/library/time/shared/xmlschema.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-describe :time_xmlschema, shared: true do
- it "parses ISO-8601 strings" do
- t = Time.utc(1985, 4, 12, 23, 20, 50, 520000)
- s = "1985-04-12T23:20:50.52Z"
- t.should == Time.xmlschema(s)
- #s.should == t.xmlschema(2)
-
- t = Time.utc(1996, 12, 20, 0, 39, 57)
- s = "1996-12-19T16:39:57-08:00"
- t.should == Time.xmlschema(s)
- # There is no way to generate time string with arbitrary timezone.
- s = "1996-12-20T00:39:57Z"
- t.should == Time.xmlschema(s)
- #assert_equal(s, t.xmlschema)
-
- t = Time.utc(1990, 12, 31, 23, 59, 60)
- s = "1990-12-31T23:59:60Z"
- t.should == Time.xmlschema(s)
- # leap second is representable only if timezone file has it.
- s = "1990-12-31T15:59:60-08:00"
- t.should == Time.xmlschema(s)
-
- begin
- Time.at(-1)
- rescue ArgumentError
- # ignore
- else
- t = Time.utc(1937, 1, 1, 11, 40, 27, 870000)
- s = "1937-01-01T12:00:27.87+00:20"
- t.should == Time.xmlschema(s)
- end
-
- # more
-
- # (Time.utc(1999, 5, 31, 13, 20, 0) + 5 * 3600).should == Time.xmlschema("1999-05-31T13:20:00-05:00")
- # (Time.local(2000, 1, 20, 12, 0, 0)).should == Time.xmlschema("2000-01-20T12:00:00")
- # (Time.utc(2000, 1, 20, 12, 0, 0)).should == Time.xmlschema("2000-01-20T12:00:00Z")
- # (Time.utc(2000, 1, 20, 12, 0, 0) - 12 * 3600).should == Time.xmlschema("2000-01-20T12:00:00+12:00")
- # (Time.utc(2000, 1, 20, 12, 0, 0) + 13 * 3600).should == Time.xmlschema("2000-01-20T12:00:00-13:00")
- # (Time.utc(2000, 3, 4, 23, 0, 0) - 3 * 3600).should == Time.xmlschema("2000-03-04T23:00:00+03:00")
- # (Time.utc(2000, 3, 4, 20, 0, 0)).should == Time.xmlschema("2000-03-04T20:00:00Z")
- # (Time.local(2000, 1, 15, 0, 0, 0)).should == Time.xmlschema("2000-01-15T00:00:00")
- # (Time.local(2000, 2, 15, 0, 0, 0)).should == Time.xmlschema("2000-02-15T00:00:00")
- # (Time.local(2000, 1, 15, 12, 0, 0)).should == Time.xmlschema("2000-01-15T12:00:00")
- # (Time.utc(2000, 1, 16, 12, 0, 0)).should == Time.xmlschema("2000-01-16T12:00:00Z")
- # (Time.local(2000, 1, 1, 12, 0, 0)).should == Time.xmlschema("2000-01-01T12:00:00")
- # (Time.utc(1999, 12, 31, 23, 0, 0)).should == Time.xmlschema("1999-12-31T23:00:00Z")
- # (Time.local(2000, 1, 16, 12, 0, 0)).should == Time.xmlschema("2000-01-16T12:00:00")
- # (Time.local(2000, 1, 16, 0, 0, 0)).should == Time.xmlschema("2000-01-16T00:00:00")
- # (Time.utc(2000, 1, 12, 12, 13, 14)).should == Time.xmlschema("2000-01-12T12:13:14Z")
- # (Time.utc(2001, 4, 17, 19, 23, 17, 300000)).should == Time.xmlschema("2001-04-17T19:23:17.3Z")
- end
-end
diff --git a/spec/ruby/library/time/to_date_spec.rb b/spec/ruby/library/time/to_date_spec.rb
deleted file mode 100644
index baeafe0847..0000000000
--- a/spec/ruby/library/time/to_date_spec.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-
-require_relative '../../spec_helper'
-require 'time'
-
-describe "Time#to_date" do
- it "yields accurate julian date for ambiguous pre-Gregorian reform value" do
- Time.utc(1582, 10, 4).to_date.jd.should == Date::ITALY - 11 # 2299150j
- end
-
- it "yields accurate julian date for Julian-Gregorian gap value" do
- Time.utc(1582, 10, 14).to_date.jd.should == Date::ITALY - 1 # 2299160j
- end
-
- it "yields accurate julian date for post-Gregorian reform value" do
- Time.utc(1582, 10, 15).to_date.jd.should == Date::ITALY # 2299161j
- end
-
- it "yields same julian day regardless of UTC time value" do
- Time.utc(1582, 10, 15, 00, 00, 00).to_date.jd.should == Date::ITALY
- Time.utc(1582, 10, 15, 23, 59, 59).to_date.jd.should == Date::ITALY
- end
-
- it "yields same julian day regardless of local time or zone" do
-
- with_timezone("Pacific/Pago_Pago", -11) do
- Time.local(1582, 10, 15, 00, 00, 00).to_date.jd.should == Date::ITALY
- Time.local(1582, 10, 15, 23, 59, 59).to_date.jd.should == Date::ITALY
- end
-
- with_timezone("Asia/Kamchatka", +12) do
- Time.local(1582, 10, 15, 00, 00, 00).to_date.jd.should == Date::ITALY
- Time.local(1582, 10, 15, 23, 59, 59).to_date.jd.should == Date::ITALY
- end
-
- end
-
- it "yields date with default Calendar reform day" do
- Time.utc(1582, 10, 4).to_date.start.should == Date::ITALY
- Time.utc(1582, 10, 14).to_date.start.should == Date::ITALY
- Time.utc(1582, 10, 15).to_date.start.should == Date::ITALY
- end
-end
diff --git a/spec/ruby/library/time/to_datetime_spec.rb b/spec/ruby/library/time/to_datetime_spec.rb
deleted file mode 100644
index c5561535b2..0000000000
--- a/spec/ruby/library/time/to_datetime_spec.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-require_relative '../../spec_helper'
-require 'time'
-
-describe "Time#to_datetime" do
- it "returns a DateTime representing the same instant" do
- time = Time.utc(2012, 12, 31, 23, 58, 59)
- datetime = time.to_datetime
- datetime.year.should == 2012
- datetime.month.should == 12
- datetime.day.should == 31
- datetime.hour.should == 23
- datetime.min.should == 58
- 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
- datetime.to_time.utc.should == time
- end
-
- it "yields a DateTime with the default Calendar reform day" do
- Time.utc(1582, 10, 4, 1, 2, 3).to_datetime.start.should == Date::ITALY
- Time.utc(1582, 10, 14, 1, 2, 3).to_datetime.start.should == Date::ITALY
- Time.utc(1582, 10, 15, 1, 2, 3).to_datetime.start.should == Date::ITALY
- end
-end
diff --git a/spec/ruby/library/time/to_time_spec.rb b/spec/ruby/library/time/to_time_spec.rb
index 7e6c75a003..d2b89cb112 100644
--- a/spec/ruby/library/time/to_time_spec.rb
+++ b/spec/ruby/library/time/to_time_spec.rb
@@ -6,10 +6,10 @@ describe "Time#to_time" do
time = Time.new(2012, 2, 21, 10, 11, 12)
with_timezone("America/Regina") do
- time.to_time.should equal time
+ time.to_time.should.equal? time
end
time2 = Time.utc(2012, 2, 21, 10, 11, 12)
- time2.to_time.should equal time2
+ time2.to_time.should.equal? time2
end
end
diff --git a/spec/ruby/library/time/xmlschema_spec.rb b/spec/ruby/library/time/xmlschema_spec.rb
index 4279311199..1f7d63979a 100644
--- a/spec/ruby/library/time/xmlschema_spec.rb
+++ b/spec/ruby/library/time/xmlschema_spec.rb
@@ -1,7 +1,56 @@
require_relative '../../spec_helper'
-require_relative 'shared/xmlschema'
require 'time'
describe "Time.xmlschema" do
- it_behaves_like :time_xmlschema, :xmlschema
+ it "parses ISO-8601 strings" do
+ t = Time.utc(1985, 4, 12, 23, 20, 50, 520000)
+ s = "1985-04-12T23:20:50.52Z"
+ t.should == Time.xmlschema(s)
+ #s.should == t.xmlschema(2)
+
+ t = Time.utc(1996, 12, 20, 0, 39, 57)
+ s = "1996-12-19T16:39:57-08:00"
+ t.should == Time.xmlschema(s)
+ # There is no way to generate time string with arbitrary timezone.
+ s = "1996-12-20T00:39:57Z"
+ t.should == Time.xmlschema(s)
+ #assert_equal(s, t.xmlschema)
+
+ t = Time.utc(1990, 12, 31, 23, 59, 60)
+ s = "1990-12-31T23:59:60Z"
+ t.should == Time.xmlschema(s)
+ # leap second is representable only if timezone file has it.
+ s = "1990-12-31T15:59:60-08:00"
+ t.should == Time.xmlschema(s)
+
+ begin
+ Time.at(-1)
+ rescue ArgumentError
+ # ignore
+ else
+ t = Time.utc(1937, 1, 1, 11, 40, 27, 870000)
+ s = "1937-01-01T12:00:27.87+00:20"
+ t.should == Time.xmlschema(s)
+ end
+
+ # more
+
+ # (Time.utc(1999, 5, 31, 13, 20, 0) + 5 * 3600).should == Time.xmlschema("1999-05-31T13:20:00-05:00")
+ # (Time.local(2000, 1, 20, 12, 0, 0)).should == Time.xmlschema("2000-01-20T12:00:00")
+ # (Time.utc(2000, 1, 20, 12, 0, 0)).should == Time.xmlschema("2000-01-20T12:00:00Z")
+ # (Time.utc(2000, 1, 20, 12, 0, 0) - 12 * 3600).should == Time.xmlschema("2000-01-20T12:00:00+12:00")
+ # (Time.utc(2000, 1, 20, 12, 0, 0) + 13 * 3600).should == Time.xmlschema("2000-01-20T12:00:00-13:00")
+ # (Time.utc(2000, 3, 4, 23, 0, 0) - 3 * 3600).should == Time.xmlschema("2000-03-04T23:00:00+03:00")
+ # (Time.utc(2000, 3, 4, 20, 0, 0)).should == Time.xmlschema("2000-03-04T20:00:00Z")
+ # (Time.local(2000, 1, 15, 0, 0, 0)).should == Time.xmlschema("2000-01-15T00:00:00")
+ # (Time.local(2000, 2, 15, 0, 0, 0)).should == Time.xmlschema("2000-02-15T00:00:00")
+ # (Time.local(2000, 1, 15, 12, 0, 0)).should == Time.xmlschema("2000-01-15T12:00:00")
+ # (Time.utc(2000, 1, 16, 12, 0, 0)).should == Time.xmlschema("2000-01-16T12:00:00Z")
+ # (Time.local(2000, 1, 1, 12, 0, 0)).should == Time.xmlschema("2000-01-01T12:00:00")
+ # (Time.utc(1999, 12, 31, 23, 0, 0)).should == Time.xmlschema("1999-12-31T23:00:00Z")
+ # (Time.local(2000, 1, 16, 12, 0, 0)).should == Time.xmlschema("2000-01-16T12:00:00")
+ # (Time.local(2000, 1, 16, 0, 0, 0)).should == Time.xmlschema("2000-01-16T00:00:00")
+ # (Time.utc(2000, 1, 12, 12, 13, 14)).should == Time.xmlschema("2000-01-12T12:13:14Z")
+ # (Time.utc(2001, 4, 17, 19, 23, 17, 300000)).should == Time.xmlschema("2001-04-17T19:23:17.3Z")
+ end
end