home_run 0.9.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/LICENSE +19 -0
- data/README.rdoc +314 -0
- data/Rakefile +136 -0
- data/bench/cpu_bench.rb +279 -0
- data/bench/dt_garbage_bench.rb +11 -0
- data/bench/dt_mem_bench.rb +14 -0
- data/bench/garbage_bench.rb +11 -0
- data/bench/mem_bench.rb +14 -0
- data/bin/home_run +91 -0
- data/default.mspec +12 -0
- data/ext/1.8/date_ext.so +0 -0
- data/ext/1.9/date_ext.so +0 -0
- data/ext/date.rb +7 -0
- data/ext/date/format.rb +842 -0
- data/ext/date_ext.c +4548 -0
- data/ext/date_parser.c +367 -0
- data/ext/date_parser.rl +134 -0
- data/ext/datetime.c +2804 -0
- data/ext/extconf.rb +6 -0
- data/spec/date/accessor_spec.rb +176 -0
- data/spec/date/add_month_spec.rb +26 -0
- data/spec/date/add_spec.rb +23 -0
- data/spec/date/boat_spec.rb +38 -0
- data/spec/date/civil_spec.rb +147 -0
- data/spec/date/commercial_spec.rb +153 -0
- data/spec/date/constants_spec.rb +44 -0
- data/spec/date/conversions_spec.rb +246 -0
- data/spec/date/day_spec.rb +73 -0
- data/spec/date/downto_spec.rb +17 -0
- data/spec/date/eql_spec.rb +16 -0
- data/spec/date/format_spec.rb +52 -0
- data/spec/date/gregorian_spec.rb +52 -0
- data/spec/date/hash_spec.rb +11 -0
- data/spec/date/julian_spec.rb +129 -0
- data/spec/date/leap_spec.rb +19 -0
- data/spec/date/minus_month_spec.rb +25 -0
- data/spec/date/minus_spec.rb +51 -0
- data/spec/date/next_prev_spec.rb +108 -0
- data/spec/date/ordinal_spec.rb +83 -0
- data/spec/date/parse_spec.rb +442 -0
- data/spec/date/parsing_spec.rb +77 -0
- data/spec/date/relationship_spec.rb +28 -0
- data/spec/date/step_spec.rb +109 -0
- data/spec/date/strftime_spec.rb +223 -0
- data/spec/date/strptime_spec.rb +201 -0
- data/spec/date/succ_spec.rb +20 -0
- data/spec/date/today_spec.rb +15 -0
- data/spec/date/upto_spec.rb +17 -0
- data/spec/datetime/accessor_spec.rb +218 -0
- data/spec/datetime/add_month_spec.rb +26 -0
- data/spec/datetime/add_spec.rb +36 -0
- data/spec/datetime/boat_spec.rb +43 -0
- data/spec/datetime/constructor_spec.rb +142 -0
- data/spec/datetime/conversions_spec.rb +54 -0
- data/spec/datetime/day_spec.rb +73 -0
- data/spec/datetime/downto_spec.rb +39 -0
- data/spec/datetime/eql_spec.rb +17 -0
- data/spec/datetime/format_spec.rb +59 -0
- data/spec/datetime/hash_spec.rb +11 -0
- data/spec/datetime/leap_spec.rb +19 -0
- data/spec/datetime/minus_month_spec.rb +25 -0
- data/spec/datetime/minus_spec.rb +77 -0
- data/spec/datetime/next_prev_spec.rb +138 -0
- data/spec/datetime/now_spec.rb +18 -0
- data/spec/datetime/parse_spec.rb +390 -0
- data/spec/datetime/parsing_spec.rb +77 -0
- data/spec/datetime/relationship_spec.rb +28 -0
- data/spec/datetime/step_spec.rb +155 -0
- data/spec/datetime/strftime_spec.rb +118 -0
- data/spec/datetime/strptime_spec.rb +117 -0
- data/spec/datetime/succ_spec.rb +24 -0
- data/spec/datetime/upto_spec.rb +39 -0
- data/spec/spec_helper.rb +59 -0
- metadata +154 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date constants" do
|
4
|
+
|
5
|
+
it "should define ITALY" do
|
6
|
+
Date::ITALY.should == 2299161 # 1582-10-15
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should define ENGLAND" do
|
10
|
+
Date::ENGLAND.should == 2361222 # 1752-09-14
|
11
|
+
end
|
12
|
+
|
13
|
+
# Fixes in 1.8.7
|
14
|
+
ruby_bug "#", "1.8.6" do
|
15
|
+
it "should define JULIAN" do
|
16
|
+
(Date::JULIAN <=> 2**30).should == 1
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Fixed in 1.8.7
|
21
|
+
ruby_bug "#", "1.8.6" do
|
22
|
+
it "should define GREGORIAN" do
|
23
|
+
(Date::GREGORIAN <=> -(2**30)).should == -1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should define MONTHNAMES" do
|
28
|
+
Date::MONTHNAMES.should == [nil] + %w(January February March April May June July
|
29
|
+
August September October November December)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should define DAYNAMES" do
|
33
|
+
Date::DAYNAMES.should == %w(Sunday Monday Tuesday Wednesday Thursday Friday Saturday)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should define ABBR_MONTHNAMES" do
|
37
|
+
Date::ABBR_MONTHNAMES.should == [nil] + %w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should define ABBR_DAYNAMES" do
|
41
|
+
Date::ABBR_DAYNAMES.should == %w(Sun Mon Tue Wed Thu Fri Sat)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,246 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date#new_start" do
|
4
|
+
it "should convert a date object into another with a new calendar reform" do
|
5
|
+
Date.civil(1582, 10, 14, Date::ENGLAND).new_start.should == Date.civil(1582, 10, 14)
|
6
|
+
Date.civil(1582, 10, 4, Date::ENGLAND).new_start.should == Date.civil(1582, 10, 4)
|
7
|
+
Date.civil(1582, 10, 15).new_start(Date::ENGLAND).should == Date.civil(1582, 10, 15, Date::ENGLAND)
|
8
|
+
Date.civil(1752, 9, 14).new_start(Date::ENGLAND).should == Date.civil(1752, 9, 14, Date::ENGLAND)
|
9
|
+
Date.civil(1752, 9, 13).new_start(Date::ENGLAND).should == Date.civil(1752, 9, 13, Date::ENGLAND)
|
10
|
+
end
|
11
|
+
|
12
|
+
ruby_version_is "" ... "1.9" do
|
13
|
+
it "#newsg should be the same as new_start" do
|
14
|
+
Date.civil(1582, 10, 14, Date::ENGLAND).newsg.should == Date.civil(1582, 10, 14, Date::ENGLAND).new_start
|
15
|
+
Date.civil(1582, 10, 14, Date::ENGLAND).newsg(1).should == Date.civil(1582, 10, 14, Date::ENGLAND).new_start(1)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "Date#italy" do
|
21
|
+
it "should convert a date object into another with the Italian calendar reform" do
|
22
|
+
Date.civil(1582, 10, 14, Date::ENGLAND).italy.should == Date.civil(1582, 10, 14)
|
23
|
+
Date.civil(1582, 10, 4, Date::ENGLAND).italy.should == Date.civil(1582, 10, 4)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "Date#england" do
|
28
|
+
it "should convert a date object into another with the English calendar reform" do
|
29
|
+
Date.civil(1582, 10, 15).england.should == Date.civil(1582, 10, 15, Date::ENGLAND)
|
30
|
+
Date.civil(1752, 9, 14).england.should == Date.civil(1752, 9, 14, Date::ENGLAND)
|
31
|
+
Date.civil(1752, 9, 13).england.should == Date.civil(1752, 9, 13, Date::ENGLAND)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "Date#julian" do
|
36
|
+
it "should convert a date object into another with the Julian calendar" do
|
37
|
+
Date.civil(1582, 10, 15).julian.should == Date.civil(1582, 10, 15, Date::JULIAN)
|
38
|
+
Date.civil(1752, 9, 14).julian.should == Date.civil(1752, 9, 14, Date::JULIAN)
|
39
|
+
Date.civil(1752, 9, 13).julian.should == Date.civil(1752, 9, 13, Date::JULIAN)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "Date#gregorian" do
|
44
|
+
it "should convert a date object into another with the Gregorian calendar" do
|
45
|
+
Date.civil(1582, 10, 14).gregorian.should == Date.civil(1582, 10, 14, Date::GREGORIAN)
|
46
|
+
Date.civil(1752, 9, 14).gregorian.should == Date.civil(1752, 9, 14, Date::GREGORIAN)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
ruby_version_is "" ... "1.9" do
|
51
|
+
describe "Date#ordinal_to_jd" do
|
52
|
+
it "should convert an ordinal date (year-day) to a Julian day number" do
|
53
|
+
Date.ordinal_to_jd(2007, 55).should == 2454156
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "Date#jd_to_ordinal" do
|
58
|
+
it "should convert a Julian day number into an ordinal date" do
|
59
|
+
Date.jd_to_ordinal(2454156).should == [2007, 55]
|
60
|
+
Date.jd_to_ordinal(2454156, 1).should == [2007, 55]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "Date#civil_to_jd" do
|
65
|
+
it "should convert a civil date into a Julian day number" do
|
66
|
+
Date.civil_to_jd(2007, 2, 24).should == 2454156
|
67
|
+
Date.civil_to_jd(2007, 2, 24, 1).should == 2454156
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "Date#jd_to_civil" do
|
72
|
+
it "should convert a Julian day into a civil date" do
|
73
|
+
Date.jd_to_civil(2454156).should == [2007, 2, 24]
|
74
|
+
Date.jd_to_civil(2454156, 1).should == [2007, 2, 24]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "Date#commercial_to_jd" do
|
79
|
+
it "should convert a commercial date (year - week - day of week) into a Julian day number" do
|
80
|
+
Date.commercial_to_jd(2007, 45, 1).should == 2454410
|
81
|
+
Date.commercial_to_jd(2007, 45, 1, 1).should == 2454410
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "Date#jd_to_commercial" do
|
86
|
+
it "should convert a Julian day number into a commercial date" do
|
87
|
+
Date.jd_to_commercial(2454410).should == [2007, 45, 1]
|
88
|
+
Date.jd_to_commercial(2454410, 1).should == [2007, 45, 1]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "Date#ajd_to_jd" do
|
93
|
+
it "should convert a Astronomical Julian day number into a Julian day number" do
|
94
|
+
Date.ajd_to_jd(2454410).should == [2454410, 0.5]
|
95
|
+
Date.ajd_to_jd(2454410, 1.0/ 2).should == [2454410, 0.5]
|
96
|
+
Date.ajd_to_jd(1).should == [1, 0.5]
|
97
|
+
Date.ajd_to_jd(1, 1).should == [1, 0.5]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "Date#jd_to_ajd" do
|
102
|
+
it "should convert a Julian day number into a Astronomical Julian day number" do
|
103
|
+
Date.jd_to_ajd(2454410, 0).should == 2454410
|
104
|
+
Date.jd_to_ajd(2454410, 1.0/ 2).should == 2454410
|
105
|
+
Date.jd_to_ajd(2454156, 0).should == 2454156
|
106
|
+
Date.jd_to_ajd(2454156, 1, 1).should == 2454156
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "Date#day_fraction_to_time" do
|
111
|
+
it "should be able to convert a day fraction into time" do
|
112
|
+
Date.day_fraction_to_time(2).should == [48, 0, 0, 0]
|
113
|
+
Date.day_fraction_to_time(1).should == [24, 0, 0, 0]
|
114
|
+
Date.day_fraction_to_time(1.0/ 2).should == [12, 0, 0, 0]
|
115
|
+
a = Date.day_fraction_to_time(1.0/ 7)
|
116
|
+
a.pop.should be_close(1.0/ 100800, 0.00003)
|
117
|
+
a.should == [3, 25, 42]
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "Date#time_to_day_fraction" do
|
122
|
+
it "should be able to convert a time into a day fraction" do
|
123
|
+
Date.time_to_day_fraction(48, 0, 0).should == 2.0
|
124
|
+
Date.time_to_day_fraction(24, 0, 0).should == 1.0
|
125
|
+
Date.time_to_day_fraction(12, 0, 0).should == 0.5
|
126
|
+
Date.time_to_day_fraction(10, 20, 10).should == 10.0/24.0 + 20.0/(24 * 60) + 10.0/(24 * 60 * 60)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "Date#amjd_to_ajd" do
|
131
|
+
it "shoud be able to convert Astronomical Modified Julian day numbers into Astronomical Julian day numbers" do
|
132
|
+
Date.amjd_to_ajd(10).should == 2400010
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "Date#ajd_to_amjd" do
|
137
|
+
it "shoud be able to convert Astronomical Julian day numbers into Astronomical Modified Julian day numbers" do
|
138
|
+
Date.ajd_to_amjd(10000010).should == 7600009
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "Date#mjd_to_jd" do
|
143
|
+
it "shoud be able to convert Modified Julian day numbers into Julian day numbers" do
|
144
|
+
Date.mjd_to_jd(2000).should == 2000 + 2400001
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe "Date#jd_to_mjd" do
|
149
|
+
it "shoud be able to convert Julian day numbers into Modified Julian day numbers" do
|
150
|
+
Date.jd_to_mjd(2500000).should == 2500000 - 2400001
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "Date#ld_to_jd" do
|
155
|
+
it "should be able to convert the number of days since the Gregorian calendar in Italy into Julian day numbers" do
|
156
|
+
Date.ld_to_jd(450000).should == 450000 + 2299160
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "Date#jd_to_ld" do
|
161
|
+
it "should be able to convert Julian day numbers into the number of days since the Gregorian calendar in Italy" do
|
162
|
+
Date.jd_to_ld(2450000).should == 2450000 - 2299160
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "Date#jd_to_wday" do
|
167
|
+
it "should be able to convert a Julian day number into a week day number" do
|
168
|
+
Date.jd_to_wday(2454482).should == 3
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe "Date instance methods" do
|
174
|
+
before do
|
175
|
+
@d = Date.civil(2008, 10, 11)
|
176
|
+
end
|
177
|
+
|
178
|
+
it "#ajd should be the same as jd" do
|
179
|
+
@d.ajd.should == @d.jd
|
180
|
+
end
|
181
|
+
|
182
|
+
it "#amjd should be the astronomical modified julian date" do
|
183
|
+
@d.amjd.should == 54750
|
184
|
+
end
|
185
|
+
|
186
|
+
it "#ld should be the days since italian calendar reform day" do
|
187
|
+
@d.ld.should == 155591
|
188
|
+
end
|
189
|
+
|
190
|
+
it "#mjd should be the modified julian date" do
|
191
|
+
@d.mjd.should == 54750
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
ruby_version_is "" ... "1.9" do
|
196
|
+
describe "Date.valid_time?" do
|
197
|
+
it " should return corresponding day fraction if valid and nil if not" do
|
198
|
+
Date.valid_time?(12, 0, 0).should == 0.5
|
199
|
+
Date.valid_time?(25, 0, 0).should == nil
|
200
|
+
Date.valid_time?(12, 61, 0).should == nil
|
201
|
+
Date.valid_time?(12, 0, 61).should == nil
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe "Date marshalling" do
|
207
|
+
it "should marshal and unmarshal correctly" do
|
208
|
+
Marshal.load(Marshal.dump(Date.jd)).should == Date.civil
|
209
|
+
Marshal.load(Marshal.dump(Date.today)).should == Date.today
|
210
|
+
Marshal.load(Marshal.dump(Date.civil(2010, 2, 4))).should == Date.civil(2010, 2, 4)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
ruby_version_is "1.9" do
|
215
|
+
describe "Date#to_date" do
|
216
|
+
it " should return the receiver" do
|
217
|
+
Date.new(2009, 1, 2).to_date.should == Date.new(2009, 1, 2)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
describe "Date#to_datetime" do
|
222
|
+
it " should return a DateTime equal to the receiver" do
|
223
|
+
Date.new(2009, 1, 2).to_datetime.should == DateTime.new(2009, 1, 2)
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
describe "Date#to_time" do
|
228
|
+
it " should return a Time in local time with the same year, month, day as the receiver" do
|
229
|
+
Date.new(2009, 1, 2).to_time.should == Time.local(2009, 1, 2)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe "Time#to_date" do
|
234
|
+
it " should return a Date with the same year, month, and day as the receiver" do
|
235
|
+
Time.local(2009, 1, 2).to_date.should == Date.new(2009, 1, 2)
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
describe "Time#to_time" do
|
240
|
+
it " should return the receiver in local time" do
|
241
|
+
Time.local(2009, 1, 2).to_time.should == Time.local(2009, 1, 2)
|
242
|
+
Time.local(2009, 1, 2).getutc.to_time.should == Time.local(2009, 1, 2)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is "1.9" do
|
4
|
+
describe "Date#sunday?" do
|
5
|
+
it "should return true if the day is a Sunday" do
|
6
|
+
Date.civil(2009,1,4).sunday?.should == true
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return false if the day is not a Sunday" do
|
10
|
+
Date.civil(2009,1,2).sunday?.should == false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "Date#monday?" do
|
15
|
+
it "should return true if the day is a Monday" do
|
16
|
+
Date.civil(2009,1,5).monday?.should == true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return false if the day is not a Monday" do
|
20
|
+
Date.civil(2009,1,2).monday?.should == false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "Date#tuesday?" do
|
25
|
+
it "should return true if the day is a Tuesday" do
|
26
|
+
Date.civil(2009,1,6).tuesday?.should == true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return false if the day is not a Tuesday" do
|
30
|
+
Date.civil(2009,1,2).tuesday?.should == false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "Date#wednesday?" do
|
35
|
+
it "should return true if the day is a Wednesday" do
|
36
|
+
Date.civil(2009,1,7).wednesday?.should == true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return false if the day is not a Tuesday" do
|
40
|
+
Date.civil(2009,1,2).wednesday?.should == false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "Date#thursday?" do
|
45
|
+
it "should return true if the day is a Thursday" do
|
46
|
+
Date.civil(2009,1,1).thursday?.should == true
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return false if the day is not a Thursday" do
|
50
|
+
Date.civil(2009,1,2).thursday?.should == false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "Date#friday?" do
|
55
|
+
it "should return true if the day is a Friday" do
|
56
|
+
Date.civil(2009,1,2).friday?.should == true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should return false if the day is not a Friday" do
|
60
|
+
Date.civil(2009,1,1).friday?.should == false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "Date#saturday?" do
|
65
|
+
it "should return true if the day is a Saturday" do
|
66
|
+
Date.civil(2009,1,3).saturday?.should == true
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should return false if the day is not a Saturday" do
|
70
|
+
Date.civil(2009,1,2).saturday?.should == false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date#downto" do
|
4
|
+
|
5
|
+
it "should be able to step backward in time" do
|
6
|
+
ds = Date.civil(2000, 4, 14)
|
7
|
+
de = Date.civil(2000, 3, 29)
|
8
|
+
count = 0
|
9
|
+
ds.downto(de) do |d|
|
10
|
+
d.should <= ds
|
11
|
+
d.should >= de
|
12
|
+
count += 1
|
13
|
+
end
|
14
|
+
count.should == 17
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date#eql?" do
|
4
|
+
it "should be able determine equality between date objects" do
|
5
|
+
Date.civil(2007, 10, 11).should eql(Date.civil(2007, 10, 11))
|
6
|
+
Date.civil(2007, 10, 11).should eql(Date.civil(2007, 10, 12) - 1)
|
7
|
+
Date.civil(2007, 10, 11).should_not eql(Date.civil(2007, 10, 12))
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be able determine equality between a date and a datetime objects" do
|
11
|
+
Date.civil(2007, 10, 11).should eql(DateTime.civil(2007, 10, 11))
|
12
|
+
Date.civil(2007, 10, 11).should eql(DateTime.civil(2007, 10, 12) - 1)
|
13
|
+
Date.civil(2007, 10, 11).should_not eql(DateTime.civil(2007, 10, 12))
|
14
|
+
Date.civil(2007, 10, 11).should_not eql(DateTime.civil(2007, 10, 11, 1))
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date formatting methods" do
|
4
|
+
it "#asctime and #ctime should use a format similar to Time" do
|
5
|
+
Date.new(2008, 1, 2).asctime.should == 'Wed Jan 2 00:00:00 2008'
|
6
|
+
Date.new(2008, 1, 2).ctime.should == 'Wed Jan 2 00:00:00 2008'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "#to_s should use an ISO8601 format" do
|
10
|
+
Date.new(2008, 1, 2).to_s.should == '2008-01-02'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "#inspect should use an ISO8601 format" do
|
14
|
+
Date.new(2008, 1, 2).inspect.should == '#<Date 2008-01-02>'
|
15
|
+
end
|
16
|
+
|
17
|
+
ruby_version_is "1.9" do
|
18
|
+
it "#httpdate should use an HTTP format" do
|
19
|
+
Date.new(2009, 1, 2).httpdate.should == "Fri, 02 Jan 2009 00:00:00 GMT"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "#iso8601 should use an ISO8601 format" do
|
23
|
+
Date.new(2009, 1, 2).iso8601.should == "2009-01-02"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "#jisx03010 should use an JIS X 0301 format" do
|
27
|
+
Date.new(2009, 1, 2).jisx0301.should == "H21.01.02"
|
28
|
+
Date.new(1988, 1, 2).jisx0301.should == "S63.01.02"
|
29
|
+
Date.new(1925, 1, 2).jisx0301.should == "T14.01.02"
|
30
|
+
Date.new(1911, 1, 2).jisx0301.should == "M44.01.02"
|
31
|
+
Date.new(1873, 1, 2).jisx0301.should == "M06.01.02"
|
32
|
+
Date.new(1872, 1, 2).jisx0301.should == "1872-01-02"
|
33
|
+
Date.new(1867, 1, 2).jisx0301.should == "1867-01-02"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "#rfc2822 should use an RFC2822 format" do
|
37
|
+
Date.new(2009, 1, 2).rfc2822.should == "Fri, 2 Jan 2009 00:00:00 +0000"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "#rfc822 should use an RFC822 format" do
|
41
|
+
Date.new(2009, 1, 2).rfc822.should == "Fri, 2 Jan 2009 00:00:00 +0000"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "#rfc3339 should use an RFC3339 format" do
|
45
|
+
Date.new(2009, 1, 2).rfc3339.should == "2009-01-02T00:00:00+00:00"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "#xmlschema should use an ISO8601 format" do
|
49
|
+
Date.new(2009, 1, 2).xmlschema.should == "2009-01-02"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|