rubysl-date 0.0.1 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +0 -1
- data/.travis.yml +7 -0
- data/README.md +2 -2
- data/Rakefile +0 -1
- data/lib/date.rb +1 -0
- data/lib/date/format.rb +1207 -0
- data/lib/rubysl/date.rb +2 -0
- data/lib/rubysl/date/date.rb +1765 -0
- data/lib/{rubysl-date → rubysl/date}/version.rb +1 -1
- data/rubysl-date.gemspec +18 -18
- data/spec/date/accessor_spec.rb +90 -0
- data/spec/date/add_month_spec.rb +29 -0
- data/spec/date/add_spec.rb +29 -0
- data/spec/date/ajd_spec.rb +5 -0
- data/spec/date/ajd_to_amjd_spec.rb +5 -0
- data/spec/date/ajd_to_jd_spec.rb +5 -0
- data/spec/date/amjd_spec.rb +5 -0
- data/spec/date/amjd_to_ajd_spec.rb +5 -0
- data/spec/date/append_spec.rb +5 -0
- data/spec/date/asctime_spec.rb +5 -0
- data/spec/date/boat_spec.rb +23 -0
- data/spec/date/case_compare_spec.rb +5 -0
- data/spec/date/civil_spec.rb +11 -0
- data/spec/date/civil_to_jd_spec.rb +16 -0
- data/spec/date/commercial_spec.rb +17 -0
- data/spec/date/commercial_to_jd_spec.rb +5 -0
- data/spec/date/comparison_spec.rb +5 -0
- data/spec/date/constants_spec.rb +110 -0
- data/spec/date/conversions_spec.rb +154 -0
- data/spec/date/ctime_spec.rb +5 -0
- data/spec/date/cwday_spec.rb +5 -0
- data/spec/date/cweek_spec.rb +5 -0
- data/spec/date/cwyear_spec.rb +5 -0
- data/spec/date/day_fraction_spec.rb +5 -0
- data/spec/date/day_fraction_to_time_spec.rb +5 -0
- data/spec/date/day_spec.rb +5 -0
- data/spec/date/downto_spec.rb +17 -0
- data/spec/date/england_spec.rb +5 -0
- data/spec/date/eql_spec.rb +11 -0
- data/spec/date/exist1_spec.rb +8 -0
- data/spec/date/exist2_spec.rb +8 -0
- data/spec/date/exist3_spec.rb +8 -0
- data/spec/date/exist_spec.rb +8 -0
- data/spec/date/existw_spec.rb +8 -0
- data/spec/date/format/bag/method_missing_spec.rb +5 -0
- data/spec/date/format/bag/to_hash_spec.rb +5 -0
- data/spec/date/gregorian_leap_spec.rb +15 -0
- data/spec/date/gregorian_spec.rb +46 -0
- data/spec/date/hash_spec.rb +7 -0
- data/spec/date/infinity/abs_spec.rb +5 -0
- data/spec/date/infinity/coerce_spec.rb +5 -0
- data/spec/date/infinity/comparison_spec.rb +5 -0
- data/spec/date/infinity/d_spec.rb +5 -0
- data/spec/date/infinity/finite_spec.rb +5 -0
- data/spec/date/infinity/infinite_spec.rb +5 -0
- data/spec/date/infinity/nan_spec.rb +5 -0
- data/spec/date/infinity/uminus_spec.rb +5 -0
- data/spec/date/infinity/uplus_spec.rb +5 -0
- data/spec/date/infinity/zero_spec.rb +5 -0
- data/spec/date/infinity_spec.rb +76 -0
- data/spec/date/inspect_spec.rb +5 -0
- data/spec/date/italy_spec.rb +5 -0
- data/spec/date/jd_spec.rb +14 -0
- data/spec/date/jd_to_ajd_spec.rb +5 -0
- data/spec/date/jd_to_civil_spec.rb +5 -0
- data/spec/date/jd_to_commercial_spec.rb +5 -0
- data/spec/date/jd_to_ld_spec.rb +5 -0
- data/spec/date/jd_to_mjd_spec.rb +5 -0
- data/spec/date/jd_to_ordinal_spec.rb +5 -0
- data/spec/date/jd_to_wday_spec.rb +5 -0
- data/spec/date/julian_leap_spec.rb +14 -0
- data/spec/date/julian_spec.rb +47 -0
- data/spec/date/ld_spec.rb +5 -0
- data/spec/date/ld_to_jd_spec.rb +5 -0
- data/spec/date/leap_spec.rb +9 -0
- data/spec/date/mday_spec.rb +5 -0
- data/spec/date/minus_month_spec.rb +22 -0
- data/spec/date/minus_spec.rb +29 -0
- data/spec/date/mjd_spec.rb +5 -0
- data/spec/date/mjd_to_jd_spec.rb +5 -0
- data/spec/date/mon_spec.rb +5 -0
- data/spec/date/month_spec.rb +5 -0
- data/spec/date/new0_spec.rb +8 -0
- data/spec/date/new1_spec.rb +8 -0
- data/spec/date/new2_spec.rb +8 -0
- data/spec/date/new3_spec.rb +8 -0
- data/spec/date/new_spec.rb +13 -0
- data/spec/date/new_start_spec.rb +5 -0
- data/spec/date/newsg_spec.rb +7 -0
- data/spec/date/neww_spec.rb +7 -0
- data/spec/date/next_spec.rb +5 -0
- data/spec/date/ns_spec.rb +11 -0
- data/spec/date/ordinal_spec.rb +7 -0
- data/spec/date/ordinal_to_jd_spec.rb +5 -0
- data/spec/date/os_spec.rb +11 -0
- data/spec/date/parse_spec.rb +173 -0
- data/spec/date/plus_spec.rb +19 -0
- data/spec/date/relationship_spec.rb +19 -0
- data/spec/date/right_shift_spec.rb +5 -0
- data/spec/date/sg_spec.rb +7 -0
- data/spec/date/shared/civil.rb +69 -0
- data/spec/date/shared/commercial.rb +62 -0
- data/spec/date/shared/jd.rb +14 -0
- data/spec/date/shared/new_bang.rb +14 -0
- data/spec/date/shared/ordinal.rb +42 -0
- data/spec/date/shared/parse.rb +54 -0
- data/spec/date/shared/parse_eu.rb +48 -0
- data/spec/date/shared/parse_us.rb +61 -0
- data/spec/date/shared/valid_civil.rb +69 -0
- data/spec/date/shared/valid_commercial.rb +66 -0
- data/spec/date/shared/valid_jd.rb +36 -0
- data/spec/date/shared/valid_ordinal.rb +60 -0
- data/spec/date/start_spec.rb +5 -0
- data/spec/date/step_spec.rb +55 -0
- data/spec/date/strftime_spec.rb +204 -0
- data/spec/date/strptime_spec.rb +161 -0
- data/spec/date/succ_spec.rb +5 -0
- data/spec/date/time_to_day_fraction_spec.rb +5 -0
- data/spec/date/to_s_spec.rb +5 -0
- data/spec/date/today_spec.rb +5 -0
- data/spec/date/upto_spec.rb +15 -0
- data/spec/date/valid_civil_spec.rb +9 -0
- data/spec/date/valid_commercial_spec.rb +9 -0
- data/spec/date/valid_date_spec.rb +6 -0
- data/spec/date/valid_jd_spec.rb +9 -0
- data/spec/date/valid_ordinal_spec.rb +9 -0
- data/spec/date/valid_time_spec.rb +5 -0
- data/spec/date/wday_spec.rb +5 -0
- data/spec/date/yday_spec.rb +5 -0
- data/spec/date/year_spec.rb +5 -0
- data/spec/date/zone_to_diff_spec.rb +5 -0
- data/spec/datetime/_strptime_spec.rb +5 -0
- data/spec/datetime/civil_spec.rb +5 -0
- data/spec/datetime/commercial_spec.rb +5 -0
- data/spec/datetime/hour_spec.rb +77 -0
- data/spec/datetime/httpdate_spec.rb +5 -0
- data/spec/datetime/iso8601_spec.rb +9 -0
- data/spec/datetime/jd_spec.rb +5 -0
- data/spec/datetime/jisx0301_spec.rb +9 -0
- data/spec/datetime/min_spec.rb +5 -0
- data/spec/datetime/minute_spec.rb +7 -0
- data/spec/datetime/new_offset_spec.rb +5 -0
- data/spec/datetime/new_spec.rb +52 -0
- data/spec/datetime/now_spec.rb +7 -0
- data/spec/datetime/offset_spec.rb +5 -0
- data/spec/datetime/ordinal_spec.rb +5 -0
- data/spec/datetime/parse_spec.rb +166 -0
- data/spec/datetime/rfc2822_spec.rb +5 -0
- data/spec/datetime/rfc3339_spec.rb +9 -0
- data/spec/datetime/rfc822_spec.rb +5 -0
- data/spec/datetime/sec_fraction_spec.rb +5 -0
- data/spec/datetime/sec_spec.rb +5 -0
- data/spec/datetime/second_fraction_spec.rb +5 -0
- data/spec/datetime/second_spec.rb +7 -0
- data/spec/datetime/shared/min.rb +77 -0
- data/spec/datetime/shared/sec.rb +65 -0
- data/spec/datetime/strftime_spec.rb +25 -0
- data/spec/datetime/strptime_spec.rb +5 -0
- data/spec/datetime/to_date_spec.rb +5 -0
- data/spec/datetime/to_datetime_spec.rb +5 -0
- data/spec/datetime/to_s_spec.rb +5 -0
- data/spec/datetime/to_time_spec.rb +5 -0
- data/spec/datetime/xmlschema_spec.rb +9 -0
- data/spec/datetime/zone_spec.rb +5 -0
- metadata +376 -88
- data/lib/rubysl-date.rb +0 -7
@@ -0,0 +1,173 @@
|
|
1
|
+
require File.expand_path('../shared/parse', __FILE__)
|
2
|
+
require File.expand_path('../shared/parse_us', __FILE__)
|
3
|
+
require File.expand_path('../shared/parse_eu', __FILE__)
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
describe "Date#parse" do
|
7
|
+
# The space separator is also different, doesn't work for only numbers
|
8
|
+
it "parses a day name into a Date object" do
|
9
|
+
d = Date.parse("friday")
|
10
|
+
d.should == Date.commercial(d.cwyear, d.cweek, 5)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "parses a month name into a Date object" do
|
14
|
+
d = Date.parse("october")
|
15
|
+
d.should == Date.civil(Date.today.year, 10)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "parses a month day into a Date object" do
|
19
|
+
d = Date.parse("5th")
|
20
|
+
d.should == Date.civil(Date.today.year, Date.today.month, 5)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Specs using numbers
|
24
|
+
it "throws an argument error for a single digit" do
|
25
|
+
lambda{ Date.parse("1") }.should raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "parses DD as month day number" do
|
29
|
+
d = Date.parse("10")
|
30
|
+
d.should == Date.civil(Date.today.year, Date.today.month, 10)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "parses DDD as year day number" do
|
34
|
+
d = Date.parse("100")
|
35
|
+
if Date.gregorian_leap?(Date.today.year)
|
36
|
+
d.should == Date.civil(Date.today.year, 4, 9)
|
37
|
+
else
|
38
|
+
d.should == Date.civil(Date.today.year, 4, 10)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "parses MMDD as month and day" do
|
43
|
+
d = Date.parse("1108")
|
44
|
+
d.should == Date.civil(Date.today.year, 11, 8)
|
45
|
+
end
|
46
|
+
|
47
|
+
ruby_version_is "" ... "1.9" do
|
48
|
+
it "parses YYDDD as year and day number" do
|
49
|
+
d = Date.parse("10100")
|
50
|
+
d.should == Date.civil(10, 4, 10)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "parses YYMMDD as year, month and day" do
|
54
|
+
d = Date.parse("201023")
|
55
|
+
d.should == Date.civil(20, 10, 23)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
ruby_version_is "1.9" do
|
60
|
+
it "parses YYDDD as year and day number in 1969--2068" do
|
61
|
+
d = Date.parse("10100")
|
62
|
+
d.should == Date.civil(2010, 4, 10)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "parses YYMMDD as year, month and day in 1969--2068" do
|
66
|
+
d = Date.parse("201023")
|
67
|
+
d.should == Date.civil(2020, 10, 23)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it "parses YYYYDDD as year and day number" do
|
72
|
+
d = Date.parse("1910100")
|
73
|
+
d.should == Date.civil(1910, 4, 10)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "parses YYYYMMDD as year, month and day number" do
|
77
|
+
d = Date.parse("19101101")
|
78
|
+
d.should == Date.civil(1910, 11, 1)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "Date#parse with '.' separator" do
|
83
|
+
before :all do
|
84
|
+
@sep = '.'
|
85
|
+
end
|
86
|
+
|
87
|
+
it_should_behave_like "date_parse"
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "Date#parse with '/' separator" do
|
91
|
+
before :all do
|
92
|
+
@sep = '/'
|
93
|
+
end
|
94
|
+
|
95
|
+
it_should_behave_like "date_parse"
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "Date#parse with ' ' separator" do
|
99
|
+
before :all do
|
100
|
+
@sep = ' '
|
101
|
+
end
|
102
|
+
|
103
|
+
it_should_behave_like "date_parse"
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "Date#parse with '/' separator US-style" do
|
107
|
+
before :all do
|
108
|
+
@sep = '/'
|
109
|
+
end
|
110
|
+
|
111
|
+
it_should_behave_like "date_parse_us"
|
112
|
+
end
|
113
|
+
|
114
|
+
ruby_version_is "" ... "1.8.7" do
|
115
|
+
describe "Date#parse with '.' separator US-style" do
|
116
|
+
before :all do
|
117
|
+
@sep = '.'
|
118
|
+
end
|
119
|
+
|
120
|
+
it_should_behave_like "date_parse_us"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "Date#parse with '-' separator EU-style" do
|
125
|
+
before :all do
|
126
|
+
@sep = '-'
|
127
|
+
end
|
128
|
+
|
129
|
+
it_should_behave_like "date_parse_eu"
|
130
|
+
end
|
131
|
+
|
132
|
+
ruby_version_is "1.8.7" do
|
133
|
+
describe "Date#parse(.)" do
|
134
|
+
it "parses YYYY.MM.DD into a Date object" do
|
135
|
+
d = Date.parse("2007.10.01")
|
136
|
+
d.year.should == 2007
|
137
|
+
d.month.should == 10
|
138
|
+
d.day.should == 1
|
139
|
+
end
|
140
|
+
|
141
|
+
it "parses DD.MM.YYYY into a Date object" do
|
142
|
+
d = Date.parse("10.01.2007")
|
143
|
+
d.year.should == 2007
|
144
|
+
d.month.should == 1
|
145
|
+
d.day.should == 10
|
146
|
+
end
|
147
|
+
|
148
|
+
ruby_version_is "" ... "1.9" do
|
149
|
+
it "parses YY.MM.DD into a Date object using the year YY" do
|
150
|
+
d = Date.parse("10.01.07")
|
151
|
+
d.year.should == 10
|
152
|
+
d.month.should == 1
|
153
|
+
d.day.should == 7
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
ruby_version_is "1.9" do
|
158
|
+
it "parses YY.MM.DD into a Date object using the year 20YY" do
|
159
|
+
d = Date.parse("10.01.07")
|
160
|
+
d.year.should == 2010
|
161
|
+
d.month.should == 1
|
162
|
+
d.day.should == 7
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
it "parses YY.MM.DD using the year digits as 20YY when given true as additional argument" do
|
167
|
+
d = Date.parse("10.01.07", true)
|
168
|
+
d.year.should == 2010
|
169
|
+
d.month.should == 1
|
170
|
+
d.day.should == 7
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
describe "Date#+" do
|
4
|
+
before :all do
|
5
|
+
@date = Date.civil(2000, 1, 1)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "returns a new Date object that is n days later than the current one" do
|
9
|
+
(@date + 31).should == Date.civil(2000, 2, 1)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "accepts a negative argument and returns a new Date that is earlier than the current one" do
|
13
|
+
(@date + -1).should == Date.civil(1999, 12, 31)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "raises TypeError if argument is not Numeric" do
|
17
|
+
lambda { Date.today + Date.today }.should raise_error(TypeError)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe "Date#===" do
|
4
|
+
|
5
|
+
it "returns 0 when comparing two equal dates" do
|
6
|
+
(Date.civil(2000, 04, 06) <=> Date.civil(2000, 04, 06)).should == 0
|
7
|
+
end
|
8
|
+
|
9
|
+
it "computes the difference between two 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 "compares to another numeric" do
|
15
|
+
(Date.civil(2000, 04, 05) <=> Date.civil(2000, 04, 06).jd).should == -1
|
16
|
+
(Date.civil(2001, 04, 05) <=> Date.civil(2000, 04, 06).jd).should == 1
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
describe :date_civil, :shared => true do
|
2
|
+
it "creates a Date for -4712 by default" do
|
3
|
+
# the #chomp calls are necessary because of RSpec
|
4
|
+
d = Date.send(@method)
|
5
|
+
d.year.should == -4712
|
6
|
+
d.month.should == 1
|
7
|
+
d.day.should == 1
|
8
|
+
d.julian?.should == true
|
9
|
+
d.jd.should == 0
|
10
|
+
end
|
11
|
+
|
12
|
+
it "creates a date with arguments" do
|
13
|
+
d = Date.send(@method, 2000, 3, 5)
|
14
|
+
d.year.should == 2000
|
15
|
+
d.month.should == 3
|
16
|
+
d.day.should == 5
|
17
|
+
d.julian?.should == false
|
18
|
+
d.jd.should == 2451609
|
19
|
+
|
20
|
+
# Should also work with years far in the past and future
|
21
|
+
|
22
|
+
d = Date.send(@method, -9000, 7, 5)
|
23
|
+
d.year.should == -9000
|
24
|
+
d.month.should == 7
|
25
|
+
d.day.should == 5
|
26
|
+
d.julian?.should == true
|
27
|
+
d.jd.should == -1566006
|
28
|
+
|
29
|
+
d = Date.send(@method, 9000, 10, 14)
|
30
|
+
d.year.should == 9000
|
31
|
+
d.month.should == 10
|
32
|
+
d.day.should == 14
|
33
|
+
d.julian?.should == false
|
34
|
+
d.jd.should == 5008529
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
it "doesn't create dates for invalid arguments" do
|
39
|
+
lambda { Date.send(@method, 2000, 13, 31) }.should raise_error(ArgumentError)
|
40
|
+
lambda { Date.send(@method, 2000, 12, 32) }.should raise_error(ArgumentError)
|
41
|
+
lambda { Date.send(@method, 2000, 2, 30) }.should raise_error(ArgumentError)
|
42
|
+
lambda { Date.send(@method, 1900, 2, 29) }.should raise_error(ArgumentError)
|
43
|
+
lambda { Date.send(@method, 2000, 2, 29) }.should_not raise_error(ArgumentError)
|
44
|
+
|
45
|
+
lambda { Date.send(@method, 1582, 10, 14) }.should raise_error(ArgumentError)
|
46
|
+
lambda { Date.send(@method, 1582, 10, 15) }.should_not raise_error(ArgumentError)
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
it "creates a Date for different calendar reform dates" do
|
51
|
+
d1 = Date.send(@method, 1582, 10, 4)
|
52
|
+
d1.succ.day.should == 15
|
53
|
+
|
54
|
+
d2 = Date.send(@method, 1582, 10, 4, Date::ENGLAND)
|
55
|
+
d2.succ.day.should == 5
|
56
|
+
end
|
57
|
+
|
58
|
+
ruby_version_is ""..."1.9.3" do
|
59
|
+
it "chooses an arbitrary reform date" do
|
60
|
+
r = Date.send(@method, 2000, 2, 3)
|
61
|
+
|
62
|
+
d3 = Date.send(@method, 2000, 2, 3, r.jd)
|
63
|
+
(d3 - 1).day.should == 20
|
64
|
+
(d3 - 1).month.should == 1
|
65
|
+
|
66
|
+
lambda { Date.send(@method, 2000, 2, 2, r.jd) }.should raise_error(ArgumentError)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
describe :date_commercial, :shared => true do
|
2
|
+
ruby_version_is "" ... "1.9" do
|
3
|
+
it "creates a Date for the day of Julian calendar reform in Italy by default" do
|
4
|
+
d = Date.send(@method)
|
5
|
+
d.year.should == 1582
|
6
|
+
d.month.should == 10
|
7
|
+
d.day.should == 15
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
ruby_version_is "1.9" do
|
12
|
+
it "creates a Date for Julian Day Number day 0 by default" do
|
13
|
+
d = Date.send(@method)
|
14
|
+
d.year.should == -4712
|
15
|
+
d.month.should == 1
|
16
|
+
d.day.should == 1
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
ruby_version_is "" ... "1.9" do
|
21
|
+
it "Creates a Date for the friday in the year and week given" do
|
22
|
+
d = Date.send(@method, 2000, 1)
|
23
|
+
d.year.should == 2000
|
24
|
+
d.month.should == 1
|
25
|
+
d.day.should == 7
|
26
|
+
d.cwday.should == 5
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
ruby_version_is "1.9" do
|
31
|
+
it "Creates a Date for the monday in the year and week given" do
|
32
|
+
d = Date.send(@method, 2000, 1)
|
33
|
+
d.year.should == 2000
|
34
|
+
d.month.should == 1
|
35
|
+
d.day.should == 3
|
36
|
+
d.cwday.should == 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "Creates a Date for the correct day given the year, week and day number" do
|
41
|
+
d = Date.send(@method, 2004, 1, 1)
|
42
|
+
d.year.should == 2003
|
43
|
+
d.month.should == 12
|
44
|
+
d.day.should == 29
|
45
|
+
d.cwday.should == 1
|
46
|
+
d.cweek.should == 1
|
47
|
+
d.cwyear.should == 2004
|
48
|
+
end
|
49
|
+
|
50
|
+
it "creates only Date objects for valid weeks" do
|
51
|
+
lambda { Date.send(@method, 2004, 53, 1) }.should_not raise_error(ArgumentError)
|
52
|
+
lambda { Date.send(@method, 2004, 53, 0) }.should raise_error(ArgumentError)
|
53
|
+
lambda { Date.send(@method, 2004, 53, 8) }.should raise_error(ArgumentError)
|
54
|
+
lambda { Date.send(@method, 2004, 54, 1) }.should raise_error(ArgumentError)
|
55
|
+
lambda { Date.send(@method, 2004, 0, 1) }.should raise_error(ArgumentError)
|
56
|
+
|
57
|
+
lambda { Date.send(@method, 2003, 52, 1) }.should_not raise_error(ArgumentError)
|
58
|
+
lambda { Date.send(@method, 2003, 53, 1) }.should raise_error(ArgumentError)
|
59
|
+
lambda { Date.send(@method, 2003, 52, 0) }.should raise_error(ArgumentError)
|
60
|
+
lambda { Date.send(@method, 2003, 52, 8) }.should raise_error(ArgumentError)
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
describe :date_jd, :shared => true do
|
2
|
+
it "constructs a Date object if passed a Julian day" do
|
3
|
+
Date.send(@method, 2454482).should == Date.civil(2008, 1, 16)
|
4
|
+
end
|
5
|
+
|
6
|
+
it "returns a Date object representing Julian day 0 (-4712-01-01) if no arguments passed"do
|
7
|
+
Date.send(@method).should == Date.civil(-4712, 1, 1)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "constructs a Date object if passed a negative number" do
|
11
|
+
Date.send(@method, -1).should == Date.civil(-4713, 12, 31)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
describe :date_new_bang, :shared => true do
|
2
|
+
|
3
|
+
it "returns a new Date object set to Astronomical Julian Day 0 if no arguments passed" do
|
4
|
+
d = Date.send(@method)
|
5
|
+
d.ajd.should == 0
|
6
|
+
end
|
7
|
+
|
8
|
+
it "accepts astronomical julian day number, offset as a fraction of a day and returns a new Date object" do
|
9
|
+
d = Date.send(@method, 10, 0.5)
|
10
|
+
d.ajd.should == 10
|
11
|
+
d.jd.should == 11
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# reference:
|
2
|
+
# October 1582 (the Gregorian calendar, Civil Date)
|
3
|
+
# S M Tu W Th F S
|
4
|
+
# 1 2 3 4 15 16
|
5
|
+
# 17 18 19 20 21 22 23
|
6
|
+
# 24 25 26 27 28 29 30
|
7
|
+
# 31
|
8
|
+
|
9
|
+
describe :date_ordinal, :shared => true do
|
10
|
+
|
11
|
+
ruby_version_is "" ... "1.9" do
|
12
|
+
it "constructs a Date object from an ordinal date" do
|
13
|
+
# October 1582 (the Gregorian calendar, Ordinal Date in 1.8)
|
14
|
+
# S M Tu W Th F S
|
15
|
+
# 274 275 276 277 288 289
|
16
|
+
# 290 291 292 293 294 295 296
|
17
|
+
# 297 298 299 300 301 302 303
|
18
|
+
# 304
|
19
|
+
Date.send(@method, 1582, 274).should == Date.civil(1582, 10, 1)
|
20
|
+
Date.send(@method, 1582, 277).should == Date.civil(1582, 10, 4)
|
21
|
+
lambda { Date.send(@method, 1582, 278) }.should raise_error(ArgumentError)
|
22
|
+
lambda { Date.send(@method, 1582, 287) }.should raise_error(ArgumentError)
|
23
|
+
Date.send(@method, 1582, 288).should == Date.civil(1582, 10, 15)
|
24
|
+
Date.send(@method, 1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
ruby_version_is "1.9" do
|
29
|
+
it "constructs a Date object from an ordinal date" do
|
30
|
+
# October 1582 (the Gregorian calendar, Ordinal Date in 1.9)
|
31
|
+
# S M Tu W Th F S
|
32
|
+
# 274 275 276 277 278 279
|
33
|
+
# 280 281 282 283 284 285 286
|
34
|
+
# 287 288 289 290 291 292 293
|
35
|
+
# 294
|
36
|
+
Date.send(@method, 1582, 274).should == Date.civil(1582, 10, 1)
|
37
|
+
Date.send(@method, 1582, 277).should == Date.civil(1582, 10, 4)
|
38
|
+
Date.send(@method, 1582, 278).should == Date.civil(1582, 10, 15)
|
39
|
+
Date.send(@method, 1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|