Skip to content

Commit 997d09f

Browse files
committed
Move Time to rely less on shared examples
1 parent fdb6fe1 commit 997d09f

6 files changed

Lines changed: 120 additions & 126 deletions

File tree

library/time/iso8601_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
require_relative '../../spec_helper'
2-
require_relative 'shared/xmlschema'
32
require 'time'
43

54
describe "Time.iso8601" do
6-
it_behaves_like :time_library_xmlschema, :iso8601
5+
it "is an alias of Time.xmlschema" do
6+
Time.method(:iso8601).should == Time.method(:xmlschema)
7+
end
78
end

library/time/rfc2822_spec.rb

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,68 @@
11
require_relative '../../spec_helper'
2-
require_relative 'shared/rfc2822'
32
require 'time'
43

54
describe "Time.rfc2822" do
6-
it_behaves_like :time_rfc2822, :rfc2822
5+
it "parses RFC-822 strings" do
6+
t1 = (Time.utc(1976, 8, 26, 14, 30) + 4 * 3600)
7+
t2 = Time.rfc2822("26 Aug 76 14:30 EDT")
8+
t1.should == t2
9+
10+
t3 = Time.utc(1976, 8, 27, 9, 32) + 7 * 3600
11+
t4 = Time.rfc2822("27 Aug 76 09:32 PDT")
12+
t3.should == t4
13+
end
14+
15+
it "parses RFC-2822 strings" do
16+
t1 = Time.utc(1997, 11, 21, 9, 55, 6) + 6 * 3600
17+
t2 = Time.rfc2822("Fri, 21 Nov 1997 09:55:06 -0600")
18+
t1.should == t2
19+
20+
t3 = Time.utc(2003, 7, 1, 10, 52, 37) - 2 * 3600
21+
t4 = Time.rfc2822("Tue, 1 Jul 2003 10:52:37 +0200")
22+
t3.should == t4
23+
24+
t5 = Time.utc(1997, 11, 21, 10, 1, 10) + 6 * 3600
25+
t6 = Time.rfc2822("Fri, 21 Nov 1997 10:01:10 -0600")
26+
t5.should == t6
27+
28+
t7 = Time.utc(1997, 11, 21, 11, 0, 0) + 6 * 3600
29+
t8 = Time.rfc2822("Fri, 21 Nov 1997 11:00:00 -0600")
30+
t7.should == t8
31+
32+
t9 = Time.utc(1997, 11, 24, 14, 22, 1) + 8 * 3600
33+
t10 = Time.rfc2822("Mon, 24 Nov 1997 14:22:01 -0800")
34+
t9.should == t10
35+
36+
begin
37+
Time.at(-1)
38+
rescue ArgumentError
39+
# ignore
40+
else
41+
t11 = Time.utc(1969, 2, 13, 23, 32, 54) + 3 * 3600 + 30 * 60
42+
t12 = Time.rfc2822("Thu, 13 Feb 1969 23:32:54 -0330")
43+
t11.should == t12
44+
45+
t13 = Time.utc(1969, 2, 13, 23, 32, 0) + 3 * 3600 + 30 * 60
46+
t14 = Time.rfc2822(" Thu,
47+
13
48+
Feb
49+
1969
50+
23:32
51+
-0330 (Newfoundland Time)")
52+
t13.should == t14
53+
end
54+
55+
t15 = Time.utc(1997, 11, 21, 9, 55, 6)
56+
t16 = Time.rfc2822("21 Nov 97 09:55:06 GMT")
57+
t15.should == t16
58+
59+
t17 = Time.utc(1997, 11, 21, 9, 55, 6) + 6 * 3600
60+
t18 = Time.rfc2822("Fri, 21 Nov 1997 09 : 55 : 06 -0600")
61+
t17.should == t18
62+
63+
-> {
64+
# inner comment is not supported.
65+
Time.rfc2822("Fri, 21 Nov 1997 09(comment): 55 : 06 -0600")
66+
}.should.raise(ArgumentError)
67+
end
768
end

library/time/rfc822_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
require_relative '../../spec_helper'
2-
require_relative 'shared/rfc2822'
32
require 'time'
43

54
describe "Time.rfc822" do
6-
it_behaves_like :time_rfc2822, :rfc822
5+
it "is an alias of Time.rfc2822" do
6+
Time.method(:rfc822).should == Time.method(:rfc2822)
7+
end
78
end

library/time/shared/rfc2822.rb

Lines changed: 0 additions & 65 deletions
This file was deleted.

library/time/shared/xmlschema.rb

Lines changed: 0 additions & 53 deletions
This file was deleted.

library/time/xmlschema_spec.rb

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,56 @@
11
require_relative '../../spec_helper'
2-
require_relative 'shared/xmlschema'
32
require 'time'
43

54
describe "Time.xmlschema" do
6-
it_behaves_like :time_library_xmlschema, :xmlschema
5+
it "parses ISO-8601 strings" do
6+
t = Time.utc(1985, 4, 12, 23, 20, 50, 520000)
7+
s = "1985-04-12T23:20:50.52Z"
8+
t.should == Time.xmlschema(s)
9+
#s.should == t.xmlschema(2)
10+
11+
t = Time.utc(1996, 12, 20, 0, 39, 57)
12+
s = "1996-12-19T16:39:57-08:00"
13+
t.should == Time.xmlschema(s)
14+
# There is no way to generate time string with arbitrary timezone.
15+
s = "1996-12-20T00:39:57Z"
16+
t.should == Time.xmlschema(s)
17+
#assert_equal(s, t.xmlschema)
18+
19+
t = Time.utc(1990, 12, 31, 23, 59, 60)
20+
s = "1990-12-31T23:59:60Z"
21+
t.should == Time.xmlschema(s)
22+
# leap second is representable only if timezone file has it.
23+
s = "1990-12-31T15:59:60-08:00"
24+
t.should == Time.xmlschema(s)
25+
26+
begin
27+
Time.at(-1)
28+
rescue ArgumentError
29+
# ignore
30+
else
31+
t = Time.utc(1937, 1, 1, 11, 40, 27, 870000)
32+
s = "1937-01-01T12:00:27.87+00:20"
33+
t.should == Time.xmlschema(s)
34+
end
35+
36+
# more
37+
38+
# (Time.utc(1999, 5, 31, 13, 20, 0) + 5 * 3600).should == Time.xmlschema("1999-05-31T13:20:00-05:00")
39+
# (Time.local(2000, 1, 20, 12, 0, 0)).should == Time.xmlschema("2000-01-20T12:00:00")
40+
# (Time.utc(2000, 1, 20, 12, 0, 0)).should == Time.xmlschema("2000-01-20T12:00:00Z")
41+
# (Time.utc(2000, 1, 20, 12, 0, 0) - 12 * 3600).should == Time.xmlschema("2000-01-20T12:00:00+12:00")
42+
# (Time.utc(2000, 1, 20, 12, 0, 0) + 13 * 3600).should == Time.xmlschema("2000-01-20T12:00:00-13:00")
43+
# (Time.utc(2000, 3, 4, 23, 0, 0) - 3 * 3600).should == Time.xmlschema("2000-03-04T23:00:00+03:00")
44+
# (Time.utc(2000, 3, 4, 20, 0, 0)).should == Time.xmlschema("2000-03-04T20:00:00Z")
45+
# (Time.local(2000, 1, 15, 0, 0, 0)).should == Time.xmlschema("2000-01-15T00:00:00")
46+
# (Time.local(2000, 2, 15, 0, 0, 0)).should == Time.xmlschema("2000-02-15T00:00:00")
47+
# (Time.local(2000, 1, 15, 12, 0, 0)).should == Time.xmlschema("2000-01-15T12:00:00")
48+
# (Time.utc(2000, 1, 16, 12, 0, 0)).should == Time.xmlschema("2000-01-16T12:00:00Z")
49+
# (Time.local(2000, 1, 1, 12, 0, 0)).should == Time.xmlschema("2000-01-01T12:00:00")
50+
# (Time.utc(1999, 12, 31, 23, 0, 0)).should == Time.xmlschema("1999-12-31T23:00:00Z")
51+
# (Time.local(2000, 1, 16, 12, 0, 0)).should == Time.xmlschema("2000-01-16T12:00:00")
52+
# (Time.local(2000, 1, 16, 0, 0, 0)).should == Time.xmlschema("2000-01-16T00:00:00")
53+
# (Time.utc(2000, 1, 12, 12, 13, 14)).should == Time.xmlschema("2000-01-12T12:13:14Z")
54+
# (Time.utc(2001, 4, 17, 19, 23, 17, 300000)).should == Time.xmlschema("2001-04-17T19:23:17.3Z")
55+
end
756
end

0 commit comments

Comments
 (0)