home_run 0.9.0-x86-mswin32-60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/format.rb +842 -0
- data/ext/date.rb +7 -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,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
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date#gregorian?" do
|
4
|
+
it "should return true" do
|
5
|
+
Date.civil(1007, 2, 27).gregorian?.should == true
|
6
|
+
Date.civil(1907, 2, 27, Date.civil(2000, 1, 1).jd).gregorian?.should == true
|
7
|
+
end
|
8
|
+
|
9
|
+
ruby_version_is "" ... "1.9" do
|
10
|
+
it "ns? should be same as gregorian?" do
|
11
|
+
Date.civil(1007, 2, 27).ns?.should == true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "Date.gregorian_leap?" do
|
17
|
+
|
18
|
+
it "should be able to determine whether a year is a leap year in the Gregorian calendar" do
|
19
|
+
Date.gregorian_leap?(1900).should == false
|
20
|
+
Date.gregorian_leap?(1999).should == false
|
21
|
+
Date.gregorian_leap?(2000).should == true
|
22
|
+
Date.gregorian_leap?(2002).should == false
|
23
|
+
Date.gregorian_leap?(2004).should == true
|
24
|
+
Date.gregorian_leap?(1901).should == false
|
25
|
+
Date.gregorian_leap?(1899).should == false
|
26
|
+
Date.gregorian_leap?(1904).should == true
|
27
|
+
Date.gregorian_leap?(1896).should == true
|
28
|
+
Date.gregorian_leap?(1999).should == false
|
29
|
+
Date.gregorian_leap?(2001).should == false
|
30
|
+
end
|
31
|
+
|
32
|
+
it ".leap? should be the same as gregorian_leap" do
|
33
|
+
Date.leap?(1900).should == Date.gregorian_leap?(1900)
|
34
|
+
Date.leap?(2000).should == Date.gregorian_leap?(2000)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
ruby_version_is "" ... "1.9" do
|
39
|
+
describe "Date" do
|
40
|
+
it ".gregorian? should return whether the first argument is greater than or equal the second" do
|
41
|
+
Date.gregorian?(1, 2).should == false
|
42
|
+
Date.gregorian?(2, 1).should == true
|
43
|
+
Date.gregorian?(1, 1).should == true
|
44
|
+
end
|
45
|
+
|
46
|
+
it ".ns? should be the same as gregorian?" do
|
47
|
+
Date.ns?(2, 1).should == Date.gregorian?(2, 1)
|
48
|
+
Date.ns?(1, 2).should == Date.gregorian?(1, 2)
|
49
|
+
Date.ns?(1, 1).should == Date.gregorian?(1, 1)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date#hash" do
|
4
|
+
it "should use the same hash value for equal dates" do
|
5
|
+
Date.civil(2004, 7, 12).hash.should == Date.civil(2004, 7, 12).hash
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should use a different hash value for different dates" do
|
9
|
+
Date.civil(2004, 7, 12).hash.should_not == Date.civil(2004, 7, 13).hash
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date.jd" do
|
4
|
+
it "should be able to construct a Date object based on the Julian day" do
|
5
|
+
Date.jd(2454482).should == Date.civil(2008, 1, 16)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be able to determine the Julian day for a Date object" do
|
9
|
+
Date.civil(2008, 1, 16).jd.should == 2454482
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have defaults" do
|
13
|
+
Date.jd.should == Date.jd(0)
|
14
|
+
Date.jd(2008).should == Date.jd(2008)
|
15
|
+
Date.jd(2008, 1).should == Date.jd(2008)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should not accept more than 2 arguments" do
|
19
|
+
proc{Date.jd(2008, 1, 1)}.should raise_error(ArgumentError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should raise ArgumentError for invalid dates" do
|
23
|
+
proc{Date.jd(Date::GREGORIAN)}.should raise_error
|
24
|
+
proc{Date.jd(Date::JULIAN)}.should raise_error
|
25
|
+
end
|
26
|
+
|
27
|
+
ruby_version_is "" ... "1.9" do
|
28
|
+
it ".new1 should be the same as jd" do
|
29
|
+
Date.new1(2454156).should == Date.jd(2454156)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "Date.new!" do
|
35
|
+
it "should be the same as jd" do
|
36
|
+
Date.new!(2454156).should == Date.jd(2454156)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should accept extra arguments" do
|
40
|
+
Date.new!.should == Date.jd(0)
|
41
|
+
Date.new!(2008).should == Date.jd(2008)
|
42
|
+
Date.new!(2008, 1).should == Date.jd(2008)
|
43
|
+
Date.new!(2008, 1, 1).should == Date.jd(2008)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not accept more than 3 arguments" do
|
47
|
+
proc{Date.new!(2008, 1, 1, 1)}.should raise_error(ArgumentError)
|
48
|
+
end
|
49
|
+
|
50
|
+
ruby_version_is "" ... "1.9" do
|
51
|
+
it "#new0 should be the same as new!" do
|
52
|
+
Date.new0(2454156).should == Date.new!(2454156)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "Date#julian?" do
|
58
|
+
it "should return false" do
|
59
|
+
Date.civil(1007, 2, 27).julian?.should == false
|
60
|
+
Date.civil(1907, 2, 27, Date.civil(2000, 1, 1).jd).julian?.should == false
|
61
|
+
end
|
62
|
+
|
63
|
+
ruby_version_is "" ... "1.9" do
|
64
|
+
it "os? should be same as julian?" do
|
65
|
+
Date.civil(1007, 2, 27).os?.should == false
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "Date.julian_leap?" do
|
71
|
+
|
72
|
+
it "should be able to determine whether a year is a leap year in the Julian calendar" do
|
73
|
+
Date.julian_leap?(1900).should == true
|
74
|
+
Date.julian_leap?(1999).should == false
|
75
|
+
Date.julian_leap?(2000).should == true
|
76
|
+
Date.julian_leap?(2002).should == false
|
77
|
+
Date.julian_leap?(2004).should == true
|
78
|
+
Date.julian_leap?(1901).should == false
|
79
|
+
Date.julian_leap?(1899).should == false
|
80
|
+
Date.julian_leap?(1904).should == true
|
81
|
+
Date.julian_leap?(1896).should == true
|
82
|
+
Date.julian_leap?(1999).should == false
|
83
|
+
Date.julian_leap?(2001).should == false
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "Date.valid_jd?" do
|
89
|
+
ruby_version_is "" ... "1.9" do
|
90
|
+
it "should be able to determine if a day number is a valid Julian day number, true for all numbers" do
|
91
|
+
# This might need to check the type of the jd parameter. Date.valid_jd?(:number) is of course
|
92
|
+
# bogus but returns itself with the current implementation
|
93
|
+
Date.valid_jd?(-100).should == -100
|
94
|
+
Date.valid_jd?(0).should == 0
|
95
|
+
Date.valid_jd?(100).should == 100
|
96
|
+
Date.valid_jd?(2454156).should == 2454156
|
97
|
+
Date.valid_jd?(2454156, 1).should == 2454156
|
98
|
+
end
|
99
|
+
|
100
|
+
it "#exist1? should be the same as valid_jd?" do
|
101
|
+
Date.exist1?(2454156, 1).should == Date.valid_jd?(2454156, 1)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
ruby_version_is "1.9" do
|
106
|
+
it "should be able to determine if a day number is a valid Julian day number, true for all numbers" do
|
107
|
+
# This might need to check the type of the jd parameter. Date.valid_jd?(:number) is of course
|
108
|
+
# bogus but returns itself with the current implementation
|
109
|
+
Date.valid_jd?(-100).should == true
|
110
|
+
Date.valid_jd?(0).should == true
|
111
|
+
Date.valid_jd?(100).should == true
|
112
|
+
Date.valid_jd?(2454156).should == true
|
113
|
+
Date.valid_jd?(2454156, 1).should == true
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
ruby_version_is "" ... "1.9" do
|
119
|
+
describe "Date" do
|
120
|
+
it ".julian? should return whether the first argument is less than the second" do
|
121
|
+
Date.julian?(1, 1).should == false
|
122
|
+
Date.julian?(1, 2).should == true
|
123
|
+
end
|
124
|
+
|
125
|
+
it ".os? should be the same as julian?" do
|
126
|
+
Date.os?(1, 2).should == Date.julian?(1, 2)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date#leap?" do
|
4
|
+
it "should be true if the current date is a leap year and no argument is given" do
|
5
|
+
Date.civil(2000, 10, 11).leap?.should == true
|
6
|
+
Date.civil(2004, 10, 11).leap?.should == true
|
7
|
+
Date.civil(2008, 10, 11).leap?.should == true
|
8
|
+
Date.civil(1996, 10, 11).leap?.should == true
|
9
|
+
Date.civil(1600, 10, 11).leap?.should == true
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be false if the current date is not a leap year and no argument is given" do
|
13
|
+
Date.civil(1700, 10, 11).leap?.should == false
|
14
|
+
Date.civil(1800, 10, 11).leap?.should == false
|
15
|
+
Date.civil(1900, 10, 11).leap?.should == false
|
16
|
+
Date.civil(1999, 10, 11).leap?.should == false
|
17
|
+
Date.civil(2001, 10, 11).leap?.should == false
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date#<<" do
|
4
|
+
|
5
|
+
it "should substract a number of months from a date" do
|
6
|
+
(Date.civil(2007, 12, 27) << 10).should == Date.civil(2007,2,27)
|
7
|
+
(Date.commercial(2007, 45, 5) << 10).should == Date.commercial(2007,2,2)
|
8
|
+
(Date.jd(2455086) << 10).should == Date.jd(2454782)
|
9
|
+
(Date.ordinal(2008, 315) << 10).should == Date.ordinal(2008, 10)
|
10
|
+
(Date.civil(2007, 12, 27) << 12).should == Date.civil(2006,12,27)
|
11
|
+
(Date.civil(2007, 12, 27) << -12).should == Date.civil(2008,12,27)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should result in the last day of a month if the day doesn't exist" do
|
15
|
+
d = Date.civil(2008,3,31) << 1
|
16
|
+
d.should == Date.civil(2008, 2, 29)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should raise an error on non numeric parameters" do
|
20
|
+
lambda { Date.civil(2007,2,27) << "hello" }.should raise_error(TypeError)
|
21
|
+
lambda { Date.civil(2007,2,27) << Date.new }.should raise_error(TypeError)
|
22
|
+
lambda { Date.civil(2007,2,27) << Object.new }.should raise_error(TypeError)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|