home_run 0.9.0-x86-mswin32
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 +135 -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,20 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date#succ" do
|
4
|
+
it "should be the next day" do
|
5
|
+
ds = Date.civil(2008, 10, 11)
|
6
|
+
ds.succ.should == Date.civil(2008, 10, 12)
|
7
|
+
ds = Date.civil(2008, 10, 31)
|
8
|
+
ds.succ.should == Date.civil(2008, 11, 1)
|
9
|
+
ds = Date.commercial(2008, 2, 7)
|
10
|
+
ds.succ.should == Date.commercial(2008, 3, 1)
|
11
|
+
ds = Date.jd(2008)
|
12
|
+
ds.succ.should == Date.jd(2009)
|
13
|
+
ds = Date.ordinal(2008, 366)
|
14
|
+
ds.succ.should == Date.ordinal(2009, 1)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be aliased as next" do
|
18
|
+
Date.civil(2008, 10, 11).next.should == Date.civil(2008, 10, 12)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date.today" do
|
4
|
+
it "should be today's date" do
|
5
|
+
t = Time.now
|
6
|
+
d = Date.today
|
7
|
+
d.year.should == t.year
|
8
|
+
d.mon.should == t.mon
|
9
|
+
d.day.should == t.day
|
10
|
+
end
|
11
|
+
|
12
|
+
it ".today should have an optional sg value" do
|
13
|
+
Date.today(1).should == Date.today
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date#upto" do
|
4
|
+
|
5
|
+
it "should be able to step forward in time" do
|
6
|
+
ds = Date.civil(2008, 10, 11)
|
7
|
+
de = Date.civil(2008, 9, 29)
|
8
|
+
count = 0
|
9
|
+
de.upto(ds) do |d|
|
10
|
+
d.should <= ds
|
11
|
+
d.should >= de
|
12
|
+
count += 1
|
13
|
+
end
|
14
|
+
count.should == 13
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,218 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "DateTime#day_fraction" do
|
4
|
+
it "should be able to determine the fraction of the day" do
|
5
|
+
DateTime.new(2008, 1, 1).day_fraction.should == 0.0
|
6
|
+
DateTime.new(2008, 1, 1, 12).day_fraction.should == 0.5
|
7
|
+
DateTime.new(2008, 1, 1, 6).day_fraction.should == 0.25
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "DateTime#hour" do
|
12
|
+
it "should be able to determine the hour of the day" do
|
13
|
+
DateTime.jd(2007, 1).hour.should == 1
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "DateTime#min" do
|
18
|
+
it "should be able to determine the minute of the day" do
|
19
|
+
DateTime.jd(2007, 1, 2).min.should == 2
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "DateTime#offset" do
|
24
|
+
it "should be able to determine the offset of the day from UTC" do
|
25
|
+
DateTime.jd(2007, 1, 2, 3, 6/24.0).offset.should == 6/24.0
|
26
|
+
DateTime.parse('2008-01-01 00:00:00+12:00').offset.should == 0.5
|
27
|
+
end
|
28
|
+
|
29
|
+
ruby_version_is "" ... "1.9" do
|
30
|
+
it "#of should be the offset as a float fraction of the day" do
|
31
|
+
DateTime.parse('2008-01-01 00:00:00+12:00').of.should == 0.5
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "DateTime#sec" do
|
37
|
+
it "should be able to determine the second of the day" do
|
38
|
+
DateTime.jd(2007, 1, 2, 3).sec.should == 3
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "DateTime#sec_fraction" do
|
43
|
+
it "should be the fraction of a second as a fraction of the day" do
|
44
|
+
DateTime.new(2008, 1, 1).sec_fraction.should == 0.0
|
45
|
+
DateTime.parse('12:13:15.678900').sec_fraction.should be_close(7.85763888888889e-06, 0.0000000000001)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "DateTime#zone" do
|
50
|
+
it "should give the offset as a string" do
|
51
|
+
DateTime.jd(0).zone.should == '+00:00'
|
52
|
+
DateTime.jd(2007, 0, 0, 0, -1/24.0).zone.should == '-01:00'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "DateTime#cwyear" do
|
57
|
+
it "should be able to determine the commercial year for a date" do
|
58
|
+
DateTime.civil(2007, 1, 17).cwyear.should == 2007
|
59
|
+
DateTime.civil(2008, 10, 28).cwyear.should == 2008
|
60
|
+
DateTime.civil(2007, 12, 31).cwyear.should == 2008
|
61
|
+
DateTime.civil(2010, 1, 1).cwyear.should == 2009
|
62
|
+
DateTime.commercial(2008, 1, 1).cwyear.should == 2008
|
63
|
+
DateTime.commercial(2008, 52, 1).cwyear.should == 2008
|
64
|
+
DateTime.jd(2454782).cwyear.should == 2008
|
65
|
+
DateTime.jd(2454832).cwyear.should == 2009
|
66
|
+
DateTime.ordinal(2008, 1).cwyear.should == 2008
|
67
|
+
DateTime.ordinal(2008, 359).cwyear.should == 2008
|
68
|
+
DateTime.ordinal(2008, 366).cwyear.should == 2009
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "DateTime#cweek" do
|
73
|
+
it "should be able to determine the commercial week for a date" do
|
74
|
+
DateTime.civil(2007, 1, 17).cweek.should == 3
|
75
|
+
DateTime.civil(2008, 10, 28).cweek.should == 44
|
76
|
+
DateTime.civil(2007, 12, 31).cweek.should == 1
|
77
|
+
DateTime.civil(2010, 1, 1).cweek.should == 53
|
78
|
+
DateTime.commercial(2008, 1, 1).cweek.should == 1
|
79
|
+
DateTime.commercial(2008, 10, 5).cweek.should == 10
|
80
|
+
DateTime.jd(2454782).cweek.should == 46
|
81
|
+
DateTime.jd(2454789).cweek.should == 47
|
82
|
+
DateTime.ordinal(2008, 1).cweek.should == 1
|
83
|
+
DateTime.ordinal(2008, 359).cweek.should == 52
|
84
|
+
DateTime.ordinal(2008, 366).cweek.should == 1
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "DateTime#cwday" do
|
89
|
+
it "should be able to determine the commercial week day for a date" do
|
90
|
+
DateTime.civil(2007, 1, 17).cwday.should == 3
|
91
|
+
DateTime.civil(2008, 10, 26).cwday.should == 7
|
92
|
+
DateTime.commercial(2008, 1, 1).cwday.should == 1
|
93
|
+
DateTime.commercial(2008, 10, 5).cwday.should == 5
|
94
|
+
DateTime.jd(2454782).cwday.should == 2
|
95
|
+
DateTime.jd(2454786).cwday.should == 6
|
96
|
+
DateTime.ordinal(2008, 1).cwday.should == 2
|
97
|
+
DateTime.ordinal(2008, 317).cwday.should == 3
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "DateTime#mday and #day" do
|
102
|
+
it "should be able to determine the day of the month for a date" do
|
103
|
+
DateTime.civil(2007, 1, 17).mday.should == 17
|
104
|
+
DateTime.civil(2008, 10, 28).mday.should == 28
|
105
|
+
DateTime.civil(2007, 1, 17).day.should == 17
|
106
|
+
DateTime.civil(2008, 10, 28).day.should == 28
|
107
|
+
DateTime.commercial(2008, 1, 1).day.should == 31
|
108
|
+
DateTime.commercial(2008, 52, 1).day.should == 22
|
109
|
+
DateTime.jd(2454782).day.should == 11
|
110
|
+
DateTime.jd(2454832).day.should == 31
|
111
|
+
DateTime.ordinal(2008, 1).day.should == 1
|
112
|
+
DateTime.ordinal(2008, 359).day.should == 24
|
113
|
+
DateTime.ordinal(2008, 366).day.should == 31
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "DateTime#jd" do
|
118
|
+
it "should be able to determine the julian date for a date" do
|
119
|
+
DateTime.civil(2007, 1, 17).jd.should == 2454118
|
120
|
+
DateTime.civil(2008, 10, 28).jd.should == 2454768
|
121
|
+
DateTime.commercial(2008, 1, 1).jd.should == 2454466
|
122
|
+
DateTime.commercial(2008, 52, 1).jd.should == 2454823
|
123
|
+
DateTime.jd(2454782).jd.should == 2454782
|
124
|
+
DateTime.jd(2454832).jd.should == 2454832
|
125
|
+
DateTime.ordinal(2008, 1).jd.should == 2454467
|
126
|
+
DateTime.ordinal(2008, 359).jd.should == 2454825
|
127
|
+
DateTime.ordinal(2008, 366).jd.should == 2454832
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "DateTime#ajd" do
|
132
|
+
it "should be a float of the astronomical julian day" do
|
133
|
+
DateTime.jd(2008).ajd.should == 2007.5
|
134
|
+
DateTime.jd(2008, 12).ajd.should == 2008
|
135
|
+
DateTime.jd(2008, 0, 0, 0, -0.5).ajd.should == 2008
|
136
|
+
DateTime.jd(2008, 12, 0, 0, -0.5).ajd.should == 2008.5
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "DateTime#amjd" do
|
141
|
+
it "#amjd should be a float of the astronomical julian day" do
|
142
|
+
DateTime.jd(2008).amjd.should == -2397993.0
|
143
|
+
DateTime.jd(2008, 12).amjd.should == -2397992.5
|
144
|
+
DateTime.jd(2008, 0, 0, 0, -0.5).amjd.should == -2397992.5
|
145
|
+
DateTime.jd(2008, 12, 0, 0, -0.5).amjd.should == -2397992.0
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "DateTime#mjd" do
|
150
|
+
it "should be able to determine the Modified Julian day for a date" do
|
151
|
+
DateTime.civil(2007, 1, 17).mjd.should == 54117
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe "DateTime#ld" do
|
156
|
+
it "should be able to determine the Modified Julian day for a date" do
|
157
|
+
DateTime.civil(2007, 1, 17).ld.should == 154958
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe "DateTime#wday" do
|
162
|
+
it "should be able to determine the week day for a date" do
|
163
|
+
DateTime.civil(2007, 1, 17).wday.should == 3
|
164
|
+
DateTime.civil(2008, 10, 26).wday.should == 0
|
165
|
+
DateTime.commercial(2008, 1, 1).wday.should == 1
|
166
|
+
DateTime.commercial(2008, 52, 1).wday.should == 1
|
167
|
+
DateTime.jd(2454782).wday.should == 2
|
168
|
+
DateTime.jd(2454832).wday.should == 3
|
169
|
+
DateTime.ordinal(2008, 1).wday.should == 2
|
170
|
+
DateTime.ordinal(2008, 170).wday.should == 3
|
171
|
+
DateTime.ordinal(2008, 366).wday.should == 3
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "DateTime#year" do
|
176
|
+
it "should be able to determine the year for a date" do
|
177
|
+
DateTime.civil(2007, 1, 17).year.should == 2007
|
178
|
+
DateTime.civil(2008, 1, 17).year.should == 2008
|
179
|
+
DateTime.commercial(2008, 1, 1).year.should == 2007
|
180
|
+
DateTime.commercial(2008, 52, 1).year.should == 2008
|
181
|
+
DateTime.jd(2454782).year.should == 2008
|
182
|
+
DateTime.jd(2454833).year.should == 2009
|
183
|
+
DateTime.ordinal(2008, 1).year.should == 2008
|
184
|
+
DateTime.ordinal(2008, 170).year.should == 2008
|
185
|
+
DateTime.ordinal(2008, 366).year.should == 2008
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe "DateTime#yday" do
|
190
|
+
it "should be able to determine the year for a date" do
|
191
|
+
DateTime.civil(2007, 1, 17).yday.should == 17
|
192
|
+
DateTime.civil(2008, 10, 28).yday.should == 302
|
193
|
+
DateTime.commercial(2008, 1, 1).yday.should == 365
|
194
|
+
DateTime.commercial(2008, 52, 1).yday.should == 357
|
195
|
+
DateTime.jd(2454782).yday.should == 316
|
196
|
+
DateTime.jd(2454832).yday.should == 366
|
197
|
+
DateTime.ordinal(2008, 1).yday.should == 1
|
198
|
+
DateTime.ordinal(2008, 170).yday.should == 170
|
199
|
+
DateTime.ordinal(2008, 366).yday.should == 366
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
describe "DateTime#mon and #month" do
|
204
|
+
it "should be able to determine the month for a date" do
|
205
|
+
DateTime.civil(2007, 1, 17).mon.should == 1
|
206
|
+
DateTime.civil(2008, 10, 28).mon.should == 10
|
207
|
+
DateTime.civil(2007, 1, 17).month.should == 1
|
208
|
+
DateTime.civil(2008, 10, 28).month.should == 10
|
209
|
+
DateTime.commercial(2008, 1, 1).mon.should == 12
|
210
|
+
DateTime.commercial(2008, 52, 1).mon.should == 12
|
211
|
+
DateTime.jd(2454782).mon.should == 11
|
212
|
+
DateTime.jd(2454832).mon.should == 12
|
213
|
+
DateTime.ordinal(2008, 1).mon.should == 1
|
214
|
+
DateTime.ordinal(2008, 170).mon.should == 6
|
215
|
+
DateTime.ordinal(2008, 366).mon.should == 12
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "DateTime#>>" do
|
4
|
+
|
5
|
+
it "should add a number of months to a DateTime" do
|
6
|
+
(DateTime.civil(2007,2,27) >> 10).should == DateTime.civil(2007, 12, 27)
|
7
|
+
(DateTime.civil(2007,2,27) >> 10).should == DateTime.civil(2007, 12, 27)
|
8
|
+
(DateTime.commercial(2007,2,2) >> 10).should == DateTime.commercial(2007, 45, 5)
|
9
|
+
(DateTime.jd(2454782) >> 10).should == DateTime.jd(2455086)
|
10
|
+
(DateTime.ordinal(2008, 10) >> 10).should == DateTime.ordinal(2008, 315)
|
11
|
+
(DateTime.civil(2007,2,27) >> 22).should == DateTime.civil(2008, 12, 27)
|
12
|
+
(DateTime.civil(2007,2,27) >> -2).should == DateTime.civil(2006, 12, 27)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should result in the last day of a month if the day doesn't exist" do
|
16
|
+
d = DateTime.civil(2008,3,31) >> 1
|
17
|
+
d.should == DateTime.civil(2008, 4, 30)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise an error on non numeric parameters" do
|
21
|
+
lambda { DateTime.civil(2007,2,27) >> "hello" }.should raise_error(TypeError)
|
22
|
+
lambda { DateTime.civil(2007,2,27) >> DateTime.new }.should raise_error(TypeError)
|
23
|
+
lambda { DateTime.civil(2007,2,27) >> Object.new }.should raise_error(TypeError)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "DateTime#+" do
|
4
|
+
|
5
|
+
it "should add a number of days to a Date" do
|
6
|
+
(DateTime.civil(2007,2,27) + 315).should == DateTime.civil(2008, 1, 8)
|
7
|
+
(DateTime.commercial(2007,2,2) + 315).should == DateTime.commercial(2007, 47, 2)
|
8
|
+
(DateTime.jd(2454782) + 315).should == DateTime.jd(2455097)
|
9
|
+
(DateTime.ordinal(2008, 10) + 315).should == DateTime.ordinal(2008, 325)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should add a fractional number of days to a Date" do
|
13
|
+
(DateTime.civil(2007,2,27) + 315.5).should == DateTime.civil(2008, 1, 8, 12)
|
14
|
+
(DateTime.commercial(2007,2,2) + 315.75).should == DateTime.commercial(2007, 47, 2, 18)
|
15
|
+
(DateTime.jd(2454782) + 315.25).should == DateTime.jd(2455097, 6)
|
16
|
+
(DateTime.ordinal(2008, 10) + 315.25).should == DateTime.ordinal(2008, 325, 6)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should add a negative number of days to a Date" do
|
20
|
+
d = DateTime.civil(2007,2,27).+(-10)
|
21
|
+
d.should == DateTime.civil(2007, 2, 17)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should add a fractional negative number of days to a Date" do
|
25
|
+
d = DateTime.civil(2007,2,27).+(-10.5)
|
26
|
+
d.should == DateTime.civil(2007, 2, 16, 12)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should raise an error on non numeric parameters" do
|
30
|
+
lambda { DateTime.civil(2007,2,27) + :hello }.should raise_error(TypeError)
|
31
|
+
lambda { DateTime.civil(2007,2,27) + "hello" }.should raise_error(TypeError)
|
32
|
+
lambda { DateTime.civil(2007,2,27) + DateTime.new(2007,2,27) }.should raise_error(TypeError)
|
33
|
+
lambda { DateTime.civil(2007,2,27) + Object.new }.should raise_error(TypeError)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "DateTime#<=>" do
|
4
|
+
|
5
|
+
it "should be able to compare two same DateTimes" do
|
6
|
+
(DateTime.civil(2000, 04, 06) <=> DateTime.civil(2000, 04, 06)).should == 0
|
7
|
+
(DateTime.civil(2000, 04, 06, 10, 12, 11) <=> DateTime.civil(2000, 04, 06, 10, 12, 11)).should == 0
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be able to compute the difference between two DateTimes" do
|
11
|
+
(DateTime.civil(2000, 04, 05) <=> DateTime.civil(2000, 04, 06)).should == -1
|
12
|
+
(DateTime.civil(2001, 04, 05) <=> DateTime.civil(2000, 04, 06)).should == 1
|
13
|
+
(DateTime.civil(2000, 04, 05, 10, 12, 13, 1/24.0) <=> DateTime.civil(2000, 04, 05, 10, 12, 13, 2/24.0)).should == 1
|
14
|
+
(DateTime.civil(2001, 04, 05, 10, 12, 13, 1/24.0) <=> DateTime.civil(2001, 04, 05, 10, 12, 13, 0)).should == -1
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be able to compare to another numeric" do
|
18
|
+
(DateTime.civil(2000, 04, 05) <=> DateTime.civil(2000, 04, 06).jd).should == -1
|
19
|
+
(DateTime.civil(2001, 04, 05) <=> DateTime.civil(2000, 04, 06).jd).should == 1
|
20
|
+
|
21
|
+
(DateTime.civil(2000, 04, 05).jd <=> 2451640).should == 0
|
22
|
+
(DateTime.civil(2000, 04, 05) <=> 2451640.00000001).should == -1
|
23
|
+
(DateTime.civil(2000, 04, 05) <=> 2451639.99999999).should == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "DateTime#between?" do
|
29
|
+
it "should be true if the DateTime falls in between the two given DateTimes" do
|
30
|
+
(DateTime.civil(2000, 04, 06).between?(DateTime.civil(2000, 04, 05), DateTime.civil(2000, 04, 07))).should == true
|
31
|
+
(DateTime.civil(2000, 04, 06).between?(DateTime.civil(2000, 04, 06), DateTime.civil(2000, 04, 07))).should == true
|
32
|
+
(DateTime.civil(2000, 04, 06).between?(DateTime.civil(2000, 04, 05), DateTime.civil(2000, 04, 06))).should == true
|
33
|
+
|
34
|
+
(DateTime.civil(2000, 04, 06, 10, 12, 11, 3/24.0).between?(DateTime.civil(2000, 04, 06, 10, 12, 11, 4/24.0), DateTime.civil(2000, 04, 06, 10, 12, 11, 2/24.0))).should == true
|
35
|
+
(DateTime.civil(2000, 04, 06, 10, 12, 11, 2/24.0).between?(DateTime.civil(2000, 04, 06, 10, 12, 11, 4/24.0), DateTime.civil(2000, 04, 06, 10, 12, 11, 2/24.0))).should == true
|
36
|
+
(DateTime.civil(2000, 04, 06, 10, 12, 11, 4/24.0).between?(DateTime.civil(2000, 04, 06, 10, 12, 11, 4/24.0), DateTime.civil(2000, 04, 06, 10, 12, 11, 2/24.0))).should == true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should be false if the DateTime does not fall in between the two given DateTimes" do
|
40
|
+
(DateTime.civil(2000, 04, 05).between?(DateTime.civil(2000, 04, 06), DateTime.civil(2000, 04, 07))).should == false
|
41
|
+
(DateTime.civil(2000, 04, 06, 10, 12, 11, 5/24.0).between?(DateTime.civil(2000, 04, 06, 10, 12, 11, 4/24.0), DateTime.civil(2000, 04, 06, 10, 12, 11, 2/24.0))).should == false
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "DateTime constructors" do
|
4
|
+
it ".civil creates a datetime with arguments" do
|
5
|
+
d = DateTime.civil(2000, 3, 5, 6, 7, 8, 1/24.0)
|
6
|
+
d.year.should == 2000
|
7
|
+
d.month.should == 3
|
8
|
+
d.day.should == 5
|
9
|
+
d.hour.should == 6
|
10
|
+
d.min.should == 7
|
11
|
+
d.sec.should == 8
|
12
|
+
d.offset.should == 1/24.0
|
13
|
+
end
|
14
|
+
|
15
|
+
it ".civil should have defaults and an optional sg value" do
|
16
|
+
DateTime.civil.should == DateTime.jd
|
17
|
+
DateTime.civil(2008).should == DateTime.civil(2008, 1, 1, 0, 0, 0, 0.0)
|
18
|
+
DateTime.civil(2008, 1).should == DateTime.civil(2008, 1, 1, 0, 0, 0, 0.0)
|
19
|
+
DateTime.civil(2008, 1, 1).should == DateTime.civil(2008, 1, 1, 0, 0, 0, 0.0)
|
20
|
+
DateTime.civil(2008, 1, 1, 0).should == DateTime.civil(2008, 1, 1, 0, 0, 0, 0.0)
|
21
|
+
DateTime.civil(2008, 1, 1, 0, 0).should == DateTime.civil(2008, 1, 1, 0, 0, 0, 0.0)
|
22
|
+
DateTime.civil(2008, 1, 1, 0, 0, 0).should == DateTime.civil(2008, 1, 1, 0, 0, 0, 0.0)
|
23
|
+
DateTime.civil(2008, 1, 1, 0, 0, 0, 0.0).should == DateTime.civil(2008, 1, 1, 0, 0, 0, 0.0)
|
24
|
+
DateTime.civil(2008, 1, 1, 1, 1, 1, 0.5, 1).should == DateTime.civil(2008, 1, 1, 1, 1, 1, 0.5)
|
25
|
+
end
|
26
|
+
|
27
|
+
it ".commercial creates a datetime with arguments" do
|
28
|
+
d = DateTime.commercial(2000, 3, 5, 6, 7, 8, 1/24.0)
|
29
|
+
d.cwyear.should == 2000
|
30
|
+
d.cweek.should == 3
|
31
|
+
d.cwday.should == 5
|
32
|
+
d.hour.should == 6
|
33
|
+
d.min.should == 7
|
34
|
+
d.sec.should == 8
|
35
|
+
d.offset.should == 1/24.0
|
36
|
+
end
|
37
|
+
|
38
|
+
ruby_version_is "1.9" do
|
39
|
+
it ".commercial should have defaults and an optional sg value" do
|
40
|
+
DateTime.commercial.should == DateTime.jd
|
41
|
+
DateTime.commercial(2008).should == DateTime.commercial(2008, 1, 1, 0, 0, 0, 0.0)
|
42
|
+
DateTime.commercial(2008, 1).should == DateTime.commercial(2008, 1, 1, 0, 0, 0, 0.0)
|
43
|
+
DateTime.commercial(2008, 1, 1).should == DateTime.commercial(2008, 1, 1, 0, 0, 0, 0.0)
|
44
|
+
DateTime.commercial(2008, 1, 1, 0).should == DateTime.commercial(2008, 1, 1, 0, 0, 0, 0.0)
|
45
|
+
DateTime.commercial(2008, 1, 1, 0, 0).should == DateTime.commercial(2008, 1, 1, 0, 0, 0, 0.0)
|
46
|
+
DateTime.commercial(2008, 1, 1, 0, 0, 0).should == DateTime.commercial(2008, 1, 1, 0, 0, 0, 0.0)
|
47
|
+
DateTime.commercial(2008, 1, 1, 0, 0, 0, 0.0).should == DateTime.commercial(2008, 1, 1, 0, 0, 0, 0.0)
|
48
|
+
DateTime.commercial(2008, 1, 1, 1, 1, 1, 0.5, 1).should == DateTime.commercial(2008, 1, 1, 1, 1, 1, 0.5)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
ruby_version_is "" ... "1.9" do
|
53
|
+
it ".commercial should have defaults and an optional sg value" do
|
54
|
+
DateTime.commercial.should == DateTime.commercial(1582, 41, 5)
|
55
|
+
DateTime.commercial(2008).should == DateTime.commercial(2008, 41, 5, 0, 0, 0, 0.0)
|
56
|
+
DateTime.commercial(2008, 1).should == DateTime.commercial(2008, 1, 5, 0, 0, 0, 0.0)
|
57
|
+
DateTime.commercial(2008, 1, 1).should == DateTime.commercial(2008, 1, 1, 0, 0, 0, 0.0)
|
58
|
+
DateTime.commercial(2008, 1, 1, 0).should == DateTime.commercial(2008, 1, 1, 0, 0, 0, 0.0)
|
59
|
+
DateTime.commercial(2008, 1, 1, 0, 0).should == DateTime.commercial(2008, 1, 1, 0, 0, 0, 0.0)
|
60
|
+
DateTime.commercial(2008, 1, 1, 0, 0, 0).should == DateTime.commercial(2008, 1, 1, 0, 0, 0, 0.0)
|
61
|
+
DateTime.commercial(2008, 1, 1, 0, 0, 0, 0.0).should == DateTime.commercial(2008, 1, 1, 0, 0, 0, 0.0)
|
62
|
+
DateTime.commercial(2008, 1, 1, 1, 1, 1, 0.5, 1).should == DateTime.commercial(2008, 1, 1, 1, 1, 1, 0.5)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it ".jd creates a datetime with arguments" do
|
67
|
+
d = DateTime.jd(2000, 6, 7, 8, 1/24.0)
|
68
|
+
d.jd.should == 2000
|
69
|
+
d.hour.should == 6
|
70
|
+
d.min.should == 7
|
71
|
+
d.sec.should == 8
|
72
|
+
d.offset.should == 1/24.0
|
73
|
+
end
|
74
|
+
|
75
|
+
it ".jd should have defaults and an optional sg value" do
|
76
|
+
DateTime.jd.should == DateTime.jd(0, 0, 0, 0, 0)
|
77
|
+
DateTime.jd(0).should == DateTime.jd(0, 0, 0, 0, 0)
|
78
|
+
DateTime.jd(0, 0).should == DateTime.jd(0, 0, 0, 0, 0)
|
79
|
+
DateTime.jd(0, 0, 0).should == DateTime.jd(0, 0, 0, 0, 0)
|
80
|
+
DateTime.jd(0, 0, 0, 0).should == DateTime.jd(0, 0, 0, 0, 0)
|
81
|
+
DateTime.jd(0, 0, 0, 0, 0).should == DateTime.jd(0, 0, 0, 0, 0)
|
82
|
+
DateTime.jd(2008, 1, 1, 1, 0.5, 1).should == DateTime.jd(2008, 1, 1, 1, 0.5)
|
83
|
+
end
|
84
|
+
|
85
|
+
it ".new! creates a datetime with arguments" do
|
86
|
+
d = DateTime.new!(2422222)
|
87
|
+
d.jd.should == 2422222
|
88
|
+
d.hour.should == 12
|
89
|
+
d.min.should == 0
|
90
|
+
d.sec.should == 0
|
91
|
+
d.offset.should == 0
|
92
|
+
|
93
|
+
d = DateTime.new!(2422222.5)
|
94
|
+
d.jd.should == 2422223
|
95
|
+
d.hour.should == 0
|
96
|
+
d.min.should == 0
|
97
|
+
d.sec.should == 0
|
98
|
+
d.offset.should == 0
|
99
|
+
|
100
|
+
d = DateTime.new!(2422222, 0.5)
|
101
|
+
d.jd.should == 2422223
|
102
|
+
d.hour.should == 0
|
103
|
+
d.min.should == 0
|
104
|
+
d.sec.should == 0
|
105
|
+
d.offset.should == 0.5
|
106
|
+
|
107
|
+
d = DateTime.new!(2422222.5, 0.5)
|
108
|
+
d.jd.should == 2422223
|
109
|
+
d.hour.should == 12
|
110
|
+
d.min.should == 0
|
111
|
+
d.sec.should == 0
|
112
|
+
d.offset.should == 0.5
|
113
|
+
end
|
114
|
+
|
115
|
+
it ".new! should have defaults and an optional sg value" do
|
116
|
+
DateTime.new!.should == DateTime.jd
|
117
|
+
DateTime.new!(0).should == DateTime.new!(0, 0)
|
118
|
+
DateTime.new!(0, 0).should == DateTime.new!(0, 0)
|
119
|
+
DateTime.new!(2008, 0.5, 1).should == DateTime.new!(2008, 0.5)
|
120
|
+
end
|
121
|
+
|
122
|
+
it ".ordinal creates a datetime with arguments" do
|
123
|
+
d = DateTime.ordinal(2000, 100, 6, 7, 8, 1/24.0)
|
124
|
+
d.year.should == 2000
|
125
|
+
d.yday.should == 100
|
126
|
+
d.hour.should == 6
|
127
|
+
d.min.should == 7
|
128
|
+
d.sec.should == 8
|
129
|
+
d.offset.should == 1/24.0
|
130
|
+
end
|
131
|
+
|
132
|
+
it ".ordinal should have defaults and an optional sg value" do
|
133
|
+
DateTime.ordinal.should == DateTime.jd
|
134
|
+
DateTime.ordinal(2008).should == DateTime.ordinal(2008, 1, 0, 0, 0, 0)
|
135
|
+
DateTime.ordinal(2008, 1).should == DateTime.ordinal(2008, 1, 0, 0, 0, 0)
|
136
|
+
DateTime.ordinal(2008, 1, 0).should == DateTime.ordinal(2008, 1, 0, 0, 0, 0)
|
137
|
+
DateTime.ordinal(2008, 1, 0, 0).should == DateTime.ordinal(2008, 1, 0, 0, 0, 0)
|
138
|
+
DateTime.ordinal(2008, 1, 0, 0, 0).should == DateTime.ordinal(2008, 1, 0, 0, 0, 0)
|
139
|
+
DateTime.ordinal(2008, 1, 0, 0, 0, 0).should == DateTime.ordinal(2008, 1, 0, 0, 0, 0)
|
140
|
+
DateTime.ordinal(2008, 1, 1, 1, 1, 0.5, 1).should == DateTime.ordinal(2008, 1, 1, 1, 1, 0.5)
|
141
|
+
end
|
142
|
+
end
|