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,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
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date#-" do
|
4
|
+
|
5
|
+
it "should substract a number of days from a Date" do
|
6
|
+
(Date.civil(2008, 1, 8) - 315).should == Date.civil(2007,2,27)
|
7
|
+
(Date.commercial(2007, 47, 2) - 315).should == Date.commercial(2007,2,2)
|
8
|
+
(Date.jd(2455097) - 315).should == Date.jd(2454782)
|
9
|
+
(Date.ordinal(2008, 325) - 315).should == Date.ordinal(2008, 10)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should substract a negative number of days from a Date" do
|
13
|
+
d = Date.civil(2007, 4, 19).-(-13)
|
14
|
+
d.should == Date.civil(2007, 5 ,2)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be able to compute the different between two dates" do
|
18
|
+
(Date.civil(2007,2,27) - Date.civil(2007,2,27)).should == 0
|
19
|
+
(Date.civil(2007,2,27) - Date.civil(2007,2,26)).should == 1
|
20
|
+
(Date.civil(2006,2,27) - Date.civil(2007,2,27)).should == -365
|
21
|
+
(Date.civil(2008,2,27) - Date.civil(2007,2,27)).should == 365
|
22
|
+
(Date.civil(2009,2,27) - Date.civil(2008,2,27)).should == 366
|
23
|
+
|
24
|
+
(Date.civil(2009,2,27) - Date.commercial(2008,2,1)).should == 417
|
25
|
+
(Date.civil(2009,2,27) - Date.jd(2454782)).should == 108
|
26
|
+
(Date.civil(2009,2,27) - Date.ordinal(2008, 10)).should == 414
|
27
|
+
|
28
|
+
(Date.commercial(2008,2,1) - Date.civil(2008,2,27)).should == -51
|
29
|
+
(Date.commercial(2008,2,1) - Date.jd(2454782)).should == -309
|
30
|
+
(Date.commercial(2008,2,1) - Date.ordinal(2008, 10)).should == -3
|
31
|
+
|
32
|
+
(Date.jd(2454782) - Date.commercial(2008,2,1)).should == 309
|
33
|
+
(Date.jd(2454782) - Date.civil(2009,2,27)).should == -108
|
34
|
+
(Date.jd(2454782) - Date.ordinal(2008, 10)).should == 306
|
35
|
+
|
36
|
+
(Date.ordinal(2008, 10) - Date.commercial(2008,2,1)).should == 3
|
37
|
+
(Date.ordinal(2008, 10) - Date.jd(2454782)).should == -306
|
38
|
+
(Date.ordinal(2008, 10) - Date.civil(2009,2,27)).should == -414
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be able to compute the difference between a Date and a DateTime" do
|
42
|
+
(Date.civil(2007, 4, 19) - DateTime.civil(2007, 4, 18, 12)).should == 0.5
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should raise an error on non numeric parameters" do
|
46
|
+
lambda { Date.civil(2007,2,27) - :hello }.should raise_error(TypeError)
|
47
|
+
lambda { Date.civil(2007,2,27) - "hello" }.should raise_error(TypeError)
|
48
|
+
lambda { Date.civil(2007,2,27) - Object.new }.should raise_error(TypeError)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is "1.9" do
|
4
|
+
describe "Date#next_day" do
|
5
|
+
it "should add a single day to a Date if no arguments" do
|
6
|
+
(Date.civil(2007,2,27).next_day).should == Date.civil(2007, 2, 28)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should add the given number of days to a Date if an argument" do
|
10
|
+
(Date.civil(2007,2,27).next_day(2)).should == Date.civil(2007, 3, 1)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should handle a negative argument by subtracting days" do
|
14
|
+
(Date.civil(2007,2,27).next_day(-2)).should == Date.civil(2007, 2, 25)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "Date#prev_day" do
|
19
|
+
it "should subtract a single day to a Date if no arguments" do
|
20
|
+
(Date.civil(2007,2,27).prev_day).should == Date.civil(2007, 2, 26)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should subtract the given number of days to a Date if an argument" do
|
24
|
+
(Date.civil(2007,2,27).prev_day(2)).should == Date.civil(2007, 2, 25)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should handle a negative argument by adding days" do
|
28
|
+
(Date.civil(2007,2,27).prev_day(-2)).should == Date.civil(2007, 3, 1)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "Date#next_month" do
|
33
|
+
it "should add a single month to a Date if no arguments" do
|
34
|
+
(Date.civil(2007,2,27).next_month).should == Date.civil(2007, 3, 27)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should add the given number of months to a Date if an argument" do
|
38
|
+
(Date.civil(2007,2,27).next_month(2)).should == Date.civil(2007, 4, 27)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should handle a negative argument by subtracting months" do
|
42
|
+
(Date.civil(2007,2,27).next_month(-2)).should == Date.civil(2006, 12, 27)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should handle adding a month where the new date is not a valid date" do
|
46
|
+
(Date.civil(2007,1,31).next_month).should == Date.civil(2007, 2, 28)
|
47
|
+
(Date.civil(2008,1,31).next_month).should == Date.civil(2008, 2, 29)
|
48
|
+
(Date.civil(2007,1,31).next_month(3)).should == Date.civil(2007, 4, 30)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "Date#prev_month" do
|
53
|
+
it "should subtract a single month to a Date if no arguments" do
|
54
|
+
(Date.civil(2007,2,27).prev_month).should == Date.civil(2007, 1, 27)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should subtract the given number of months to a Date if an argument" do
|
58
|
+
(Date.civil(2007,2,27).prev_month(2)).should == Date.civil(2006, 12, 27)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should handle a negative argument by adding months" do
|
62
|
+
(Date.civil(2007,2,27).prev_month(-2)).should == Date.civil(2007, 4, 27)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should handle subtracting a month where the new date is not a valid date" do
|
66
|
+
(Date.civil(2007,3,31).prev_month).should == Date.civil(2007, 2, 28)
|
67
|
+
(Date.civil(2008,3,31).prev_month).should == Date.civil(2008, 2, 29)
|
68
|
+
(Date.civil(2007,3,31).prev_month(4)).should == Date.civil(2006, 11, 30)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "Date#next_year" do
|
73
|
+
it "should add a single year to a Date if no arguments" do
|
74
|
+
(Date.civil(2007,2,27).next_year).should == Date.civil(2008, 2, 27)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should add the given number of years to a Date if an argument" do
|
78
|
+
(Date.civil(2007,2,27).next_year(2)).should == Date.civil(2009, 2, 27)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should handle a negative argument by subtracting years" do
|
82
|
+
(Date.civil(2007,2,27).next_year(-2)).should == Date.civil(2005, 2, 27)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should handle adding a year where the new date is not a valid date" do
|
86
|
+
(Date.civil(2008,2,29).next_year).should == Date.civil(2009, 2, 28)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "Date#prev_year" do
|
91
|
+
it "should add a single year to a Date if no arguments" do
|
92
|
+
(Date.civil(2007,2,27).prev_year).should == Date.civil(2006, 2, 27)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should add the given number of years to a Date if an argument" do
|
96
|
+
(Date.civil(2007,2,27).prev_year(2)).should == Date.civil(2005, 2, 27)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should handle a negative argument by subtracting years" do
|
100
|
+
(Date.civil(2007,2,27).prev_year(-2)).should == Date.civil(2009, 2, 27)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should handle adding a year where the new date is not a valid date" do
|
104
|
+
(Date.civil(2008,2,29).prev_year).should == Date.civil(2007, 2, 28)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date.ordinal" do
|
4
|
+
|
5
|
+
it "should be able to construct a Date object from an ordinal date" do
|
6
|
+
Date.ordinal(1582, 274).should == Date.civil(1582, 10, 1)
|
7
|
+
Date.ordinal(1582, 277).should == Date.civil(1582, 10, 4)
|
8
|
+
Date.ordinal(1582, 288).should == Date.civil(1582, 10, 15)
|
9
|
+
Date.ordinal(1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have defaults and an optional sg value" do
|
13
|
+
Date.ordinal.should == Date.jd
|
14
|
+
Date.ordinal(2008).should == Date.ordinal(2008, 1)
|
15
|
+
Date.ordinal(2008, 1, 1).should == Date.ordinal(2008, 1)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should not accept more than 3 arguments" do
|
19
|
+
proc{Date.ordinal(2008, 1, 1, 1)}.should raise_error(ArgumentError)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raises errors for invalid dates" do
|
23
|
+
lambda { Date.ordinal(2007, 366) }.should raise_error(ArgumentError)
|
24
|
+
lambda { Date.ordinal(2008, 366) }.should_not raise_error(ArgumentError)
|
25
|
+
lambda { Date.ordinal(2008, 367) }.should raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
|
28
|
+
ruby_version_is "" ... "1.9" do
|
29
|
+
it ".new2 should be the same as ordinal" do
|
30
|
+
Date.new2(2008, 10).should == Date.ordinal(2008, 10)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "Date.valid_ordinal?" do
|
36
|
+
|
37
|
+
ruby_version_is "" ... "1.9" do
|
38
|
+
it "should be able to determine if the date is a valid ordinal date" do
|
39
|
+
Date.valid_ordinal?(1582, 277).should == Date.civil(1582, 10, 4).jd
|
40
|
+
Date.valid_ordinal?(1582, 278).should == Date.civil(1582, 10, 5).jd
|
41
|
+
Date.valid_ordinal?(1582, 287).should == Date.civil(1582, 10, 14).jd
|
42
|
+
Date.valid_ordinal?(1582, 288).should == Date.civil(1582, 10, 15).jd
|
43
|
+
Date.valid_ordinal?(1582, 287, Date::ENGLAND).should_not == nil
|
44
|
+
Date.valid_ordinal?(1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND).jd
|
45
|
+
|
46
|
+
Date.valid_ordinal?(2007, 55).should == 2454156
|
47
|
+
Date.valid_ordinal?(2007, 55, 1).should == 2454156
|
48
|
+
Date.valid_ordinal?(2007, 367, 1).should == nil
|
49
|
+
end
|
50
|
+
|
51
|
+
it "#exist2? should be the same as valid_ordinal?" do
|
52
|
+
Date.exist2?(2007, 55, 1).should == Date.valid_ordinal?(2007, 55)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should be able to handle negative day numbers" do
|
56
|
+
Date.valid_ordinal?(1582, -89).should == Date.civil(1582, 10, 4).jd
|
57
|
+
Date.valid_ordinal?(1582, -88).should == Date.civil(1582, 10, 5).jd
|
58
|
+
Date.valid_ordinal?(1582, -79).should == Date.civil(1582, 10, 14).jd
|
59
|
+
Date.valid_ordinal?(1582, -78).should == Date.civil(1582, 10, 15).jd
|
60
|
+
Date.valid_ordinal?(2007, -100).should == Date.valid_ordinal?(2007, 266)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
ruby_version_is "1.9" do
|
65
|
+
it "should be able to determine if the date is a valid ordinal date" do
|
66
|
+
Date.valid_ordinal?(1582, 277).should == true
|
67
|
+
Date.valid_ordinal?(1582, 278).should == true
|
68
|
+
Date.valid_ordinal?(1582, 287).should == true
|
69
|
+
Date.valid_ordinal?(1582, 288).should == true
|
70
|
+
|
71
|
+
Date.valid_ordinal?(2007, 55).should == true
|
72
|
+
Date.valid_ordinal?(2007, 55, 1).should == true
|
73
|
+
Date.valid_ordinal?(2007, 367, 1).should == false
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should be able to handle negative day numbers" do
|
77
|
+
Date.valid_ordinal?(1582, -79).should == true
|
78
|
+
Date.valid_ordinal?(1582, -78).should == true
|
79
|
+
Date.valid_ordinal?(2007, -100).should == true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|