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
data/ext/extconf.rb
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
$CFLAGS << " -O2 -Wall#{' -DRUBY19' if RUBY_VERSION >= '1.9.0'}#{' -DRUBY186' if RUBY_VERSION < '1.8.7'}"
|
3
|
+
$CFLAGS << ' -Wno-extra' if $CFLAGS =~ /-Wextra/
|
4
|
+
$CFLAGS << ' -g -ggdb -rdynamic -O0 -DDEBUG' if ENV['DEBUG']
|
5
|
+
$objs = ['date_ext.o']
|
6
|
+
create_makefile("date_ext")
|
@@ -0,0 +1,176 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date#ajd" do
|
4
|
+
it "should be able to determine the Astronomical Julian day for a date" do
|
5
|
+
Date.civil(2007, 1, 17).ajd.should == 2454118
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "Date#amjd" do
|
10
|
+
it "should be able to determine the Astronomical Modified Julian day for a date" do
|
11
|
+
Date.civil(2007, 1, 17).amjd.should == 54117
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "Date#day_fraction" do
|
16
|
+
it "should be able to determine the day fraction for a date" do
|
17
|
+
Date.civil(2007, 1, 17).day_fraction.should == 0
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "Date#jd" do
|
22
|
+
it "should be able to determine the julian date for a date" do
|
23
|
+
Date.civil(2007, 1, 17).jd.should == 2454118
|
24
|
+
Date.civil(2008, 10, 28).jd.should == 2454768
|
25
|
+
Date.commercial(2008, 1, 1).jd.should == 2454466
|
26
|
+
Date.commercial(2008, 52, 1).jd.should == 2454823
|
27
|
+
Date.jd(2454782).jd.should == 2454782
|
28
|
+
Date.jd(2454832).jd.should == 2454832
|
29
|
+
Date.ordinal(2008, 1).jd.should == 2454467
|
30
|
+
Date.ordinal(2008, 359).jd.should == 2454825
|
31
|
+
Date.ordinal(2008, 366).jd.should == 2454832
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "Date#mjd" do
|
36
|
+
it "should be able to determine the Modified Julian day for a date" do
|
37
|
+
Date.civil(2007, 1, 17).mjd.should == 54117
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "Date#ld" do
|
42
|
+
it "should be able to determine the Modified Julian day for a date" do
|
43
|
+
Date.civil(2007, 1, 17).ld.should == 154958
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "Date#year" do
|
48
|
+
it "should be able to determine the year for a date" do
|
49
|
+
Date.civil(2007, 1, 17).year.should == 2007
|
50
|
+
Date.civil(2008, 1, 17).year.should == 2008
|
51
|
+
Date.commercial(2008, 1, 1).year.should == 2007
|
52
|
+
Date.commercial(2008, 52, 1).year.should == 2008
|
53
|
+
Date.jd(2454782).year.should == 2008
|
54
|
+
Date.jd(2454833).year.should == 2009
|
55
|
+
Date.ordinal(2008, 1).year.should == 2008
|
56
|
+
Date.ordinal(2008, 170).year.should == 2008
|
57
|
+
Date.ordinal(2008, 366).year.should == 2008
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "Date#yday" do
|
62
|
+
it "should be able to determine the year for a date" do
|
63
|
+
Date.civil(2007, 1, 17).yday.should == 17
|
64
|
+
Date.civil(2008, 10, 28).yday.should == 302
|
65
|
+
Date.commercial(2008, 1, 1).yday.should == 365
|
66
|
+
Date.commercial(2008, 52, 1).yday.should == 357
|
67
|
+
Date.jd(2454782).yday.should == 316
|
68
|
+
Date.jd(2454832).yday.should == 366
|
69
|
+
Date.ordinal(2008, 1).yday.should == 1
|
70
|
+
Date.ordinal(2008, 170).yday.should == 170
|
71
|
+
Date.ordinal(2008, 366).yday.should == 366
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "Date#mon and #month" do
|
76
|
+
it "should be able to determine the month for a date" do
|
77
|
+
Date.civil(2007, 1, 17).mon.should == 1
|
78
|
+
Date.civil(2008, 10, 28).mon.should == 10
|
79
|
+
Date.civil(2007, 1, 17).month.should == 1
|
80
|
+
Date.civil(2008, 10, 28).month.should == 10
|
81
|
+
Date.commercial(2008, 1, 1).mon.should == 12
|
82
|
+
Date.commercial(2008, 52, 1).mon.should == 12
|
83
|
+
Date.jd(2454782).mon.should == 11
|
84
|
+
Date.jd(2454832).mon.should == 12
|
85
|
+
Date.ordinal(2008, 1).mon.should == 1
|
86
|
+
Date.ordinal(2008, 170).mon.should == 6
|
87
|
+
Date.ordinal(2008, 366).mon.should == 12
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "Date#mday and #day" do
|
92
|
+
it "should be able to determine the day of the month for a date" do
|
93
|
+
Date.civil(2007, 1, 17).mday.should == 17
|
94
|
+
Date.civil(2008, 10, 28).mday.should == 28
|
95
|
+
Date.civil(2007, 1, 17).day.should == 17
|
96
|
+
Date.civil(2008, 10, 28).day.should == 28
|
97
|
+
Date.commercial(2008, 1, 1).day.should == 31
|
98
|
+
Date.commercial(2008, 52, 1).day.should == 22
|
99
|
+
Date.jd(2454782).day.should == 11
|
100
|
+
Date.jd(2454832).day.should == 31
|
101
|
+
Date.ordinal(2008, 1).day.should == 1
|
102
|
+
Date.ordinal(2008, 359).day.should == 24
|
103
|
+
Date.ordinal(2008, 366).day.should == 31
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "Date#wday" do
|
108
|
+
it "should be able to determine the week day for a date" do
|
109
|
+
Date.civil(2007, 1, 17).wday.should == 3
|
110
|
+
Date.civil(2008, 10, 26).wday.should == 0
|
111
|
+
Date.commercial(2008, 1, 1).wday.should == 1
|
112
|
+
Date.commercial(2008, 52, 1).wday.should == 1
|
113
|
+
Date.jd(2454782).wday.should == 2
|
114
|
+
Date.jd(2454832).wday.should == 3
|
115
|
+
Date.ordinal(2008, 1).wday.should == 2
|
116
|
+
Date.ordinal(2008, 170).wday.should == 3
|
117
|
+
Date.ordinal(2008, 366).wday.should == 3
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "Date#cwyear" do
|
122
|
+
it "should be able to determine the commercial year for a date" do
|
123
|
+
Date.civil(2007, 1, 17).cwyear.should == 2007
|
124
|
+
Date.civil(2008, 10, 28).cwyear.should == 2008
|
125
|
+
Date.civil(2007, 12, 31).cwyear.should == 2008
|
126
|
+
Date.civil(2010, 1, 1).cwyear.should == 2009
|
127
|
+
Date.commercial(2008, 1, 1).cwyear.should == 2008
|
128
|
+
Date.commercial(2008, 52, 1).cwyear.should == 2008
|
129
|
+
Date.jd(2454782).cwyear.should == 2008
|
130
|
+
Date.jd(2454832).cwyear.should == 2009
|
131
|
+
Date.ordinal(2008, 1).cwyear.should == 2008
|
132
|
+
Date.ordinal(2008, 359).cwyear.should == 2008
|
133
|
+
Date.ordinal(2008, 366).cwyear.should == 2009
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "Date#cweek" do
|
138
|
+
it "should be able to determine the commercial week for a date" do
|
139
|
+
Date.civil(2007, 1, 17).cweek.should == 3
|
140
|
+
Date.civil(2008, 10, 28).cweek.should == 44
|
141
|
+
Date.civil(2007, 12, 31).cweek.should == 1
|
142
|
+
Date.civil(2010, 1, 1).cweek.should == 53
|
143
|
+
Date.commercial(2008, 1, 1).cweek.should == 1
|
144
|
+
Date.commercial(2008, 10, 5).cweek.should == 10
|
145
|
+
Date.jd(2454782).cweek.should == 46
|
146
|
+
Date.jd(2454789).cweek.should == 47
|
147
|
+
Date.ordinal(2008, 1).cweek.should == 1
|
148
|
+
Date.ordinal(2008, 359).cweek.should == 52
|
149
|
+
Date.ordinal(2008, 366).cweek.should == 1
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "Date#cwday" do
|
154
|
+
it "should be able to determine the commercial week day for a date" do
|
155
|
+
Date.civil(2007, 1, 17).cwday.should == 3
|
156
|
+
Date.civil(2008, 10, 26).cwday.should == 7
|
157
|
+
Date.commercial(2008, 1, 1).cwday.should == 1
|
158
|
+
Date.commercial(2008, 10, 5).cwday.should == 5
|
159
|
+
Date.jd(2454782).cwday.should == 2
|
160
|
+
Date.jd(2454786).cwday.should == 6
|
161
|
+
Date.ordinal(2008, 1).cwday.should == 2
|
162
|
+
Date.ordinal(2008, 317).cwday.should == 3
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "Date#start" do
|
167
|
+
it "#start should be less than a low number" do
|
168
|
+
Date.civil(2008, 10, 11).start.should < -(2**30)
|
169
|
+
end
|
170
|
+
|
171
|
+
ruby_version_is "" ... "1.9" do
|
172
|
+
it "#sg should be less than a low number" do
|
173
|
+
Date.civil(2008, 10, 11).sg.should < -(2**30)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date#>>" do
|
4
|
+
|
5
|
+
it "should add a number of months to a Date" do
|
6
|
+
(Date.civil(2007,2,27) >> 10).should == Date.civil(2007, 12, 27)
|
7
|
+
(Date.civil(2007,2,27) >> 10).should == Date.civil(2007, 12, 27)
|
8
|
+
(Date.commercial(2007,2,2) >> 10).should == Date.commercial(2007, 45, 5)
|
9
|
+
(Date.jd(2454782) >> 10).should == Date.jd(2455086)
|
10
|
+
(Date.ordinal(2008, 10) >> 10).should == Date.ordinal(2008, 315)
|
11
|
+
(Date.civil(2007,2,27) >> 22).should == Date.civil(2008, 12, 27)
|
12
|
+
(Date.civil(2007,2,27) >> -2).should == Date.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 = Date.civil(2008,3,31) >> 1
|
17
|
+
d.should == Date.civil(2008, 4, 30)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise an error on non numeric parameters" do
|
21
|
+
lambda { Date.civil(2007,2,27) >> "hello" }.should raise_error(TypeError)
|
22
|
+
lambda { Date.civil(2007,2,27) >> Date.new }.should raise_error(TypeError)
|
23
|
+
lambda { Date.civil(2007,2,27) >> Object.new }.should raise_error(TypeError)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date#+" do
|
4
|
+
|
5
|
+
it "should add a number of days to a Date" do
|
6
|
+
(Date.civil(2007,2,27) + 315).should == Date.civil(2008, 1, 8)
|
7
|
+
(Date.commercial(2007,2,2) + 315).should == Date.commercial(2007, 47, 2)
|
8
|
+
(Date.jd(2454782) + 315).should == Date.jd(2455097)
|
9
|
+
(Date.ordinal(2008, 10) + 315).should == Date.ordinal(2008, 325)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should add a negative number of days to a Date" do
|
13
|
+
d = Date.civil(2007,2,27).+(-10)
|
14
|
+
d.should == Date.civil(2007, 2, 17)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should raise an error on non numeric parameters" do
|
18
|
+
lambda { Date.civil(2007,2,27) + "hello" }.should raise_error(TypeError)
|
19
|
+
lambda { Date.civil(2007,2,27) + Date.new }.should raise_error(TypeError)
|
20
|
+
lambda { Date.civil(2007,2,27) + Object.new }.should raise_error(TypeError)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date#<=>" do
|
4
|
+
|
5
|
+
it "should be able to compare two same dates" do
|
6
|
+
(Date.civil(2000, 04, 06) <=> Date.civil(2000, 04, 06)).should == 0
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should be able to compare two different dates" do
|
10
|
+
(Date.civil(2000, 04, 05) <=> Date.civil(2000, 04, 06)).should == -1
|
11
|
+
(Date.civil(2001, 04, 05) <=> Date.civil(2000, 04, 06)).should == 1
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should be able to compare a Date to a DateTime" do
|
15
|
+
(Date.civil(2000, 04, 06) <=> DateTime.civil(2000, 04, 06)).should == 0
|
16
|
+
(Date.civil(2000, 04, 05) <=> DateTime.civil(2000, 04, 06)).should == -1
|
17
|
+
(Date.civil(2000, 04, 07) <=> DateTime.civil(2000, 04, 06)).should == 1
|
18
|
+
(Date.civil(2000, 04, 05) <=> DateTime.civil(2000, 04, 05, 1)).should == -1
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be able to compare to another numeric" do
|
22
|
+
(Date.civil(2000, 04, 05) <=> Date.civil(2000, 04, 06).jd).should == -1
|
23
|
+
(Date.civil(2001, 04, 05) <=> Date.civil(2000, 04, 06).jd).should == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "Date#between?" do
|
29
|
+
it "should be true if the date falls in between the two given dates" do
|
30
|
+
(Date.civil(2000, 04, 06).between?(Date.civil(2000, 04, 05), Date.civil(2000, 04, 07))).should == true
|
31
|
+
(Date.civil(2000, 04, 06).between?(Date.civil(2000, 04, 06), Date.civil(2000, 04, 07))).should == true
|
32
|
+
(Date.civil(2000, 04, 06).between?(Date.civil(2000, 04, 05), Date.civil(2000, 04, 06))).should == true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should be false if the date does not fall in between the two given dates" do
|
36
|
+
(Date.civil(2000, 04, 05).between?(Date.civil(2000, 04, 06), Date.civil(2000, 04, 07))).should == false
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe :date_civil, :shared => true do
|
4
|
+
it "creates a Date with jd 0 by default" do
|
5
|
+
d = Date.send(@method)
|
6
|
+
d.year.should == -4713
|
7
|
+
d.month.should == 11
|
8
|
+
d.day.should == 24
|
9
|
+
d.julian?.should == false
|
10
|
+
d.jd.should == 0
|
11
|
+
end
|
12
|
+
|
13
|
+
it "creates a date with arguments" do
|
14
|
+
d = Date.send(@method, 2000, 3, 5)
|
15
|
+
d.year.should == 2000
|
16
|
+
d.month.should == 3
|
17
|
+
d.day.should == 5
|
18
|
+
d.julian?.should == false
|
19
|
+
d.jd.should == 2451609
|
20
|
+
|
21
|
+
# Should also work with years far in the past and future
|
22
|
+
|
23
|
+
d = Date.send(@method, -9000, 7, 5)
|
24
|
+
d.year.should == -9000
|
25
|
+
d.month.should == 7
|
26
|
+
d.day.should == 5
|
27
|
+
d.julian?.should == false
|
28
|
+
d.jd.should == -1565937
|
29
|
+
|
30
|
+
d = Date.send(@method, 9000, 10, 14)
|
31
|
+
d.year.should == 9000
|
32
|
+
d.month.should == 10
|
33
|
+
d.day.should == 14
|
34
|
+
d.julian?.should == false
|
35
|
+
d.jd.should == 5008529
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
it "raises errors for invalid dates" do
|
40
|
+
lambda { Date.send(@method, 2000, 13, 31) }.should raise_error(ArgumentError)
|
41
|
+
lambda { Date.send(@method, 2000, 12, 32) }.should raise_error(ArgumentError)
|
42
|
+
lambda { Date.send(@method, 2000, 2, 30) }.should raise_error(ArgumentError)
|
43
|
+
lambda { Date.send(@method, 1900, 2, 29) }.should raise_error(ArgumentError)
|
44
|
+
lambda { Date.send(@method, 2000, 2, 29) }.should_not raise_error(ArgumentError)
|
45
|
+
|
46
|
+
lambda { Date.send(@method, 1582, 10, 15) }.should_not raise_error(ArgumentError)
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "Date.civil" do
|
52
|
+
it_behaves_like(:date_civil, :civil)
|
53
|
+
|
54
|
+
it "should have defaults and an optional sg value" do
|
55
|
+
Date.civil.should == Date.jd
|
56
|
+
Date.civil(2008).should == Date.civil(2008, 1, 1)
|
57
|
+
Date.civil(2008, 1).should == Date.civil(2008, 1, 1)
|
58
|
+
Date.civil(2008, 1, 1).should == Date.civil(2008, 1, 1)
|
59
|
+
Date.civil(2008, 1, 1, 1).should == Date.civil(2008, 1, 1)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should not accept more than 4 arguments" do
|
63
|
+
proc{Date.civil(2008, 1, 1, 1, 1)}.should raise_error(ArgumentError)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should raise ArgumentError for invalid dates" do
|
67
|
+
proc{Date.civil(2008, 2, 30)}.should raise_error(ArgumentError)
|
68
|
+
proc{Date.civil(2009, 2, 29)}.should raise_error(ArgumentError)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "Date.new" do
|
73
|
+
it_behaves_like(:date_civil, :new)
|
74
|
+
end
|
75
|
+
|
76
|
+
ruby_version_is "" ... "1.9" do
|
77
|
+
describe "Date.new3" do
|
78
|
+
it_behaves_like(:date_civil, :new3)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "Date.valid_civil?" do
|
83
|
+
|
84
|
+
ruby_version_is "" ... "1.9" do
|
85
|
+
it "should be able to determine if a date is valid" do
|
86
|
+
Date.valid_civil?(1582, 10, 14).should == Date.civil(1582, 10, 14).jd
|
87
|
+
Date.valid_civil?(1582, 10, 15).should == Date.civil(1582, 10, 15).jd
|
88
|
+
Date.valid_civil?(1582, 10, 14, Date::ENGLAND).should_not == nil
|
89
|
+
Date.valid_civil?(1582, 10, 14, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND).jd
|
90
|
+
Date.valid_civil?(2007, 2, 24).should == 2454156
|
91
|
+
Date.valid_civil?(2007, 2, 24, 1).should == 2454156
|
92
|
+
Date.valid_civil?(2007, 2, 30, 1).should == nil
|
93
|
+
end
|
94
|
+
|
95
|
+
it "#valid_date? should be the same as valid_civil?" do
|
96
|
+
Date.valid_date?(2007, 2, 24, 1).should == Date.valid_civil?(2007, 2, 24, 1)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "#exist? should be the same as valid_date?" do
|
100
|
+
Date.exist?(2007, 2, 24, 1).should == Date.valid_date?(2007, 2, 24, 1)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "#exist3? should be the same as valid_date?" do
|
104
|
+
Date.exist3?(2007, 2, 24, 1).should == Date.valid_date?(2007, 2, 24, 1)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should be able to handle negative months and days" do
|
108
|
+
Date.valid_civil?(1582, -3, -31).should == Date.civil(1582, 10, 1).jd
|
109
|
+
Date.valid_civil?(1582, -3, -28).should == Date.civil(1582, 10, 4).jd
|
110
|
+
Date.valid_civil?(1582, -3, -27).should == Date.civil(1582, 10, 5).jd
|
111
|
+
Date.valid_civil?(1582, -3, -22).should == Date.civil(1582, 10, 10).jd
|
112
|
+
Date.valid_civil?(1582, -3, -21).should == Date.civil(1582, 10, 11).jd
|
113
|
+
Date.valid_civil?(1582, -3, -18).should == Date.civil(1582, 10, 14).jd
|
114
|
+
Date.valid_civil?(1582, -3, -17).should == Date.civil(1582, 10, 15).jd
|
115
|
+
|
116
|
+
Date.valid_civil?(2007, -11, -10).should == Date.civil(2007, 2, 19).jd
|
117
|
+
Date.valid_civil?(2008, -11, -10).should == Date.civil(2008, 2, 20).jd
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
ruby_version_is "1.9" do
|
122
|
+
it "should be able to determine if a date is valid" do
|
123
|
+
Date.valid_civil?(1582, 10, 14).should == true
|
124
|
+
Date.valid_civil?(1582, 10, 15).should == true
|
125
|
+
Date.valid_civil?(1582, 10, 14, Date::ENGLAND).should == true
|
126
|
+
Date.valid_civil?(2007, 2, 24).should == true
|
127
|
+
Date.valid_civil?(2007, 2, 24, 1).should == true
|
128
|
+
Date.valid_civil?(2007, 2, 30, 1).should == false
|
129
|
+
end
|
130
|
+
|
131
|
+
it "#valid_date? should be the same as valid_civil?" do
|
132
|
+
Date.valid_date?(2007, 2, 24, 1).should == Date.valid_civil?(2007, 2, 24, 1)
|
133
|
+
Date.valid_date?(2007, 2, 30, 1).should == Date.valid_civil?(2007, 2, 30, 1)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should be able to handle negative months and days" do
|
137
|
+
Date.valid_civil?(1582, -3, -22).should == true
|
138
|
+
Date.valid_civil?(1582, -3, -21).should == true
|
139
|
+
Date.valid_civil?(1582, -3, -18).should == true
|
140
|
+
Date.valid_civil?(1582, -3, -17).should == true
|
141
|
+
|
142
|
+
Date.valid_civil?(2007, -11, -10).should == true
|
143
|
+
Date.valid_civil?(2008, -11, -10).should == true
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe :date_commercial, :shared => true do
|
4
|
+
ruby_version_is "" ... "1.9" do
|
5
|
+
it "creates a Date for the day of Julian calendar reform in Italy by default" do
|
6
|
+
d = Date.send(@method)
|
7
|
+
d.year.should == 1582
|
8
|
+
d.month.should == 10
|
9
|
+
d.day.should == 15
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
ruby_version_is "1.9" do
|
14
|
+
it "creates a Date for Julian Day Number day 0 by default" do
|
15
|
+
Date.send(@method).jd.should == 0
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
ruby_version_is "" ... "1.9" do
|
20
|
+
it "Creates a Date for the friday in the year and week given" do
|
21
|
+
d = Date.send(@method, 2000, 1)
|
22
|
+
d.year.should == 2000
|
23
|
+
d.month.should == 1
|
24
|
+
d.day.should == 7
|
25
|
+
d.cwday.should == 5
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
ruby_version_is "1.9" do
|
30
|
+
it "Creates a Date for the monday in the year and week given" do
|
31
|
+
d = Date.send(@method, 2000, 1)
|
32
|
+
d.year.should == 2000
|
33
|
+
d.month.should == 1
|
34
|
+
d.day.should == 3
|
35
|
+
d.cwday.should == 1
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it "Creates a Date for the correct day given the year, week and day number" do
|
40
|
+
d = Date.send(@method, 2004, 1, 1)
|
41
|
+
d.year.should == 2003
|
42
|
+
d.month.should == 12
|
43
|
+
d.day.should == 29
|
44
|
+
d.cwday.should == 1
|
45
|
+
d.cweek.should == 1
|
46
|
+
d.cwyear.should == 2004
|
47
|
+
end
|
48
|
+
|
49
|
+
it "raises errors for invalid dates" do
|
50
|
+
lambda { Date.send(@method, 2004, 53, 1) }.should_not raise_error(ArgumentError)
|
51
|
+
lambda { Date.send(@method, 2004, 53, 0) }.should raise_error(ArgumentError)
|
52
|
+
lambda { Date.send(@method, 2004, 53, 8) }.should raise_error(ArgumentError)
|
53
|
+
lambda { Date.send(@method, 2004, 54, 1) }.should raise_error(ArgumentError)
|
54
|
+
lambda { Date.send(@method, 2004, 0, 1) }.should raise_error(ArgumentError)
|
55
|
+
|
56
|
+
lambda { Date.send(@method, 2003, 52, 1) }.should_not raise_error(ArgumentError)
|
57
|
+
lambda { Date.send(@method, 2003, 53, 1) }.should raise_error(ArgumentError)
|
58
|
+
lambda { Date.send(@method, 2003, 52, 0) }.should raise_error(ArgumentError)
|
59
|
+
lambda { Date.send(@method, 2003, 52, 8) }.should raise_error(ArgumentError)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "Date.commercial" do
|
64
|
+
it_behaves_like(:date_commercial, :commercial)
|
65
|
+
|
66
|
+
ruby_version_is "" ... "1.9" do
|
67
|
+
it "should have defaults and an optional sg value" do
|
68
|
+
Date.commercial.should == Date.commercial(1582, 41, 5)
|
69
|
+
Date.commercial(2008).should == Date.commercial(2008, 41, 5)
|
70
|
+
Date.commercial(2008, 1).should == Date.commercial(2008, 1, 5)
|
71
|
+
Date.commercial(2008, 1, 1).should == Date.commercial(2008, 1, 1)
|
72
|
+
Date.commercial(2008, 1, 1, 1).should == Date.commercial(2008, 1, 1)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
ruby_version_is "1.9" do
|
77
|
+
it "should have defaults and an optional sg value" do
|
78
|
+
Date.commercial.should == Date.jd
|
79
|
+
Date.commercial(2008).should == Date.commercial(2008, 1, 1)
|
80
|
+
Date.commercial(2008, 1).should == Date.commercial(2008, 1, 1)
|
81
|
+
Date.commercial(2008, 1, 1).should == Date.commercial(2008, 1, 1)
|
82
|
+
Date.commercial(2008, 1, 1, 1).should == Date.commercial(2008, 1, 1)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it ".should not accept more than 4 arguments" do
|
87
|
+
proc{Date.commercial(2008, 1, 1, 1, 1)}.should raise_error(ArgumentError)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should raise ArgumentError for invalid dates" do
|
91
|
+
proc{Date.commercial(2008, 54, 6)}.should raise_error(ArgumentError)
|
92
|
+
proc{Date.commercial(2009, 1, 8)}.should raise_error(ArgumentError)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
ruby_version_is "" ... "1.9" do
|
97
|
+
describe "Date.neww" do
|
98
|
+
it_behaves_like(:date_commercial, :neww)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "Date.valid_commercial?" do
|
103
|
+
|
104
|
+
ruby_version_is "" ... "1.9" do
|
105
|
+
it "should be able to determine if the date is a valid commercial date" do
|
106
|
+
Date.valid_commercial?(1582, 41, 4).should == Date.civil(1582, 10, 14).jd
|
107
|
+
Date.valid_commercial?(1582, 41, 5).should == Date.civil(1582, 10, 15).jd
|
108
|
+
|
109
|
+
Date.valid_commercial?(1582, 41, 4, Date::ENGLAND).should == Date.civil(1582, 10, 14).jd
|
110
|
+
Date.valid_commercial?(1752, 37, 4, Date::ENGLAND).should == Date.civil(1752, 9, 14, Date::ENGLAND).jd
|
111
|
+
|
112
|
+
Date.valid_commercial?(2007, 45, 1).should == 2454410
|
113
|
+
Date.valid_commercial?(2007, 45, 1, 1).should == 2454410
|
114
|
+
Date.valid_commercial?(2007, 54, 1, 1).should == nil
|
115
|
+
end
|
116
|
+
|
117
|
+
it "#existw? should be the same as valid_commercial?" do
|
118
|
+
Date.existw?(2007, 45, 1, 1).should == Date.valid_commercial?(2007, 45, 1, 1)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should be able to handle negative week and day numbers" do
|
122
|
+
Date.valid_commercial?(1582, -12, -4).should == Date.civil(1582, 10, 14).jd
|
123
|
+
Date.valid_commercial?(1582, -12, -3).should == Date.civil(1582, 10, 15).jd
|
124
|
+
|
125
|
+
Date.valid_commercial?(2007, -44, -2).should == Date.civil(2007, 3, 3).jd
|
126
|
+
Date.valid_commercial?(2008, -44, -2).should == Date.civil(2008, 3, 1).jd
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
ruby_version_is "1.9" do
|
131
|
+
it "should be able to determine if the date is a valid commercial date" do
|
132
|
+
Date.valid_commercial?(1582, 39, 4).should == true
|
133
|
+
Date.valid_commercial?(1582, 39, 5).should == true
|
134
|
+
Date.valid_commercial?(1582, 41, 4).should == true
|
135
|
+
Date.valid_commercial?(1582, 41, 5).should == true
|
136
|
+
Date.valid_commercial?(1582, 41, 4, Date::ENGLAND).should == true
|
137
|
+
Date.valid_commercial?(1752, 37, 4, Date::ENGLAND).should == true
|
138
|
+
|
139
|
+
Date.valid_commercial?(2007, 45, 1).should == true
|
140
|
+
Date.valid_commercial?(2007, 45, 1, 1).should == true
|
141
|
+
Date.valid_commercial?(2007, 54, 1, 1).should == false
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should be able to handle negative week and day numbers" do
|
145
|
+
Date.valid_commercial?(1582, -12, -4).should == true
|
146
|
+
Date.valid_commercial?(1582, -12, -3).should == true
|
147
|
+
|
148
|
+
Date.valid_commercial?(2007, -44, -2).should == true
|
149
|
+
Date.valid_commercial?(2008, -44, -2).should == true
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|