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,54 @@
|
|
1
|
+
describe :date_parse, :shared => true do
|
2
|
+
it "can parse a mmm-YYYY string into a Date object" do
|
3
|
+
d = Date.parse("feb#{@sep}2008")
|
4
|
+
d.year.should == 2008
|
5
|
+
d.month.should == 2
|
6
|
+
d.day.should == 1
|
7
|
+
end
|
8
|
+
|
9
|
+
it "can parse a 'DD mmm YYYY' string into a Date object" do
|
10
|
+
d = Date.parse("23#{@sep}feb#{@sep}2008")
|
11
|
+
d.year.should == 2008
|
12
|
+
d.month.should == 2
|
13
|
+
d.day.should == 23
|
14
|
+
end
|
15
|
+
|
16
|
+
it "can parse a 'mmm DD YYYY' string into a Date object" do
|
17
|
+
d = Date.parse("23#{@sep}feb#{@sep}2008")
|
18
|
+
d.year.should == 2008
|
19
|
+
d.month.should == 2
|
20
|
+
d.day.should == 23
|
21
|
+
end
|
22
|
+
|
23
|
+
it "can parse a 'YYYY mmm DD' string into a Date object" do
|
24
|
+
d = Date.parse("2008#{@sep}feb#{@sep}23")
|
25
|
+
d.year.should == 2008
|
26
|
+
d.month.should == 2
|
27
|
+
d.day.should == 23
|
28
|
+
end
|
29
|
+
|
30
|
+
it "can parse a month name and day into a Date object" do
|
31
|
+
d = Date.parse("november#{@sep}5th")
|
32
|
+
d.should == Date.civil(Date.today.year, 11, 5)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "can parse a month name, day and year into a Date object" do
|
36
|
+
d = Date.parse("november#{@sep}5th#{@sep}2005")
|
37
|
+
d.should == Date.civil(2005, 11, 5)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "can parse a year, month name and day into a Date object" do
|
41
|
+
d = Date.parse("2005#{@sep}november#{@sep}5th")
|
42
|
+
d.should == Date.civil(2005, 11, 5)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "can parse a year, day and month name into a Date object" do
|
46
|
+
d = Date.parse("5th#{@sep}november#{@sep}2005")
|
47
|
+
d.should == Date.civil(2005, 11, 5)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "can handle negative year numbers" do
|
51
|
+
d = Date.parse("5th#{@sep}november#{@sep}-2005")
|
52
|
+
d.should == Date.civil(-2005, 11, 5)
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
describe :date_parse_eu, :shared => true do
|
2
|
+
# The - separator let's it work like European format, so it as a different spec
|
3
|
+
it "can parse a YYYY-MM-DD string into a Date object" do
|
4
|
+
d = Date.parse("2007#{@sep}10#{@sep}01")
|
5
|
+
d.year.should == 2007
|
6
|
+
d.month.should == 10
|
7
|
+
d.day.should == 1
|
8
|
+
end
|
9
|
+
|
10
|
+
it "can parse a MM-DD-YYYY string into a Date object" do
|
11
|
+
d = Date.parse("10#{@sep}01#{@sep}2007")
|
12
|
+
d.year.should == 2007
|
13
|
+
d.month.should == 1
|
14
|
+
d.day.should == 10
|
15
|
+
end
|
16
|
+
|
17
|
+
ruby_version_is "" ... "1.9" do
|
18
|
+
it "can parse a MM-DD-YY string into a Date object" do
|
19
|
+
d = Date.parse("10#{@sep}01#{@sep}07")
|
20
|
+
d.year.should == 10
|
21
|
+
d.month.should == 1
|
22
|
+
d.day.should == 7
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
ruby_version_is "1.9" do
|
27
|
+
it "can parse a MM-DD-YY string into a Date object" do
|
28
|
+
d = Date.parse("10#{@sep}01#{@sep}07")
|
29
|
+
d.year.should == 2010
|
30
|
+
d.month.should == 1
|
31
|
+
d.day.should == 7
|
32
|
+
end
|
33
|
+
|
34
|
+
it "can parse a MM-DD-YY string into a Date object NOT using the year digits as 20XX" do
|
35
|
+
d = Date.parse("10#{@sep}01#{@sep}07", false)
|
36
|
+
d.year.should == 10
|
37
|
+
d.month.should == 1
|
38
|
+
d.day.should == 7
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "can parse a MM-DD-YY string into a Date object using the year digits as 20XX" do
|
43
|
+
d = Date.parse("10#{@sep}01#{@sep}07", true)
|
44
|
+
d.year.should == 2010
|
45
|
+
d.month.should == 1
|
46
|
+
d.day.should == 7
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
describe :date_parse_us, :shared => true do
|
2
|
+
it "parses a YYYY#{@sep}MM#{@sep}DD string into a Date object" do
|
3
|
+
d = Date.parse("2007#{@sep}10#{@sep}01")
|
4
|
+
d.year.should == 2007
|
5
|
+
d.month.should == 10
|
6
|
+
d.day.should == 1
|
7
|
+
end
|
8
|
+
|
9
|
+
ruby_version_is "" ... "1.9" do
|
10
|
+
it "parses a MM#{@sep}DD#{@sep}YYYY string into a Date object" do
|
11
|
+
d = Date.parse("10#{@sep}01#{@sep}2007")
|
12
|
+
d.year.should == 2007
|
13
|
+
d.month.should == 10
|
14
|
+
d.day.should == 1
|
15
|
+
end
|
16
|
+
|
17
|
+
it "parses a MM#{@sep}DD#{@sep}YY string into a Date object" do
|
18
|
+
d = Date.parse("10#{@sep}01#{@sep}07")
|
19
|
+
d.year.should == 7
|
20
|
+
d.month.should == 10
|
21
|
+
d.day.should == 1
|
22
|
+
end
|
23
|
+
|
24
|
+
it "parses a MM#{@sep}DD#{@sep}YY string into a Date object using the year digits as 20XX" do
|
25
|
+
d = Date.parse("10#{@sep}01#{@sep}07", true)
|
26
|
+
d.year.should == 2007
|
27
|
+
d.month.should == 10
|
28
|
+
d.day.should == 1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
ruby_version_is "1.9" do
|
33
|
+
it "parses a MM#{@sep}DD#{@sep}YYYY string into a Date object" do
|
34
|
+
d = Date.parse("10#{@sep}01#{@sep}2007")
|
35
|
+
d.year.should == 2007
|
36
|
+
d.month.should == 1
|
37
|
+
d.day.should == 10
|
38
|
+
end
|
39
|
+
|
40
|
+
it "parses a MM#{@sep}DD#{@sep}YY string into a Date object" do
|
41
|
+
d = Date.parse("10#{@sep}01#{@sep}07")
|
42
|
+
d.year.should == 2010
|
43
|
+
d.month.should == 1
|
44
|
+
d.day.should == 7
|
45
|
+
end
|
46
|
+
|
47
|
+
it "parses a MM#{@sep}DD#{@sep}YY string into a Date object NOT using the year digits as 20XX" do
|
48
|
+
d = Date.parse("10#{@sep}01#{@sep}07", false)
|
49
|
+
d.year.should == 10
|
50
|
+
d.month.should == 1
|
51
|
+
d.day.should == 7
|
52
|
+
end
|
53
|
+
|
54
|
+
it "parses a MM#{@sep}DD#{@sep}YY string into a Date object using the year digits as 20XX" do
|
55
|
+
d = Date.parse("10#{@sep}01#{@sep}07", true)
|
56
|
+
d.year.should == 2010
|
57
|
+
d.month.should == 1
|
58
|
+
d.day.should == 7
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
describe :date_valid_civil?, :shared => true do
|
2
|
+
|
3
|
+
# reference:
|
4
|
+
# October 1582 (the Gregorian calendar, Civil Date)
|
5
|
+
# S M Tu W Th F S
|
6
|
+
# 1 2 3 4 15 16
|
7
|
+
# 17 18 19 20 21 22 23
|
8
|
+
# 24 25 26 27 28 29 30
|
9
|
+
# 31
|
10
|
+
|
11
|
+
ruby_version_is "" ... "1.9" do
|
12
|
+
it "returns the corresponding Julian Day Number if it is a valid civil date" do
|
13
|
+
Date.send(@method, 1582, 10, 15).should == Date.civil(1582, 10, 15).jd
|
14
|
+
Date.send(@method, 1582, 10, 14, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND).jd
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns nil if it is not a valid civil date" do
|
18
|
+
Date.send(@method, 1582, 10, 14).should be_nil
|
19
|
+
Date.send(@method, 1582, 10, 14, Date::ENGLAND).should_not be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "handles negative months and days" do
|
23
|
+
# October 1582 (the Gregorian calendar, Civil Date in 1.8)
|
24
|
+
# S M Tu W Th F S
|
25
|
+
# -31 -30 -29 -28 -17 -16
|
26
|
+
# -15 -14 -13 -12 -11 -10 -9
|
27
|
+
# -8 -7 -6 -5 -4 -3 -2
|
28
|
+
# -1
|
29
|
+
Date.send(@method, 1582, -3, -31).should == Date.civil(1582, 10, 1).jd
|
30
|
+
Date.send(@method, 1582, -3, -28).should == Date.civil(1582, 10, 4).jd
|
31
|
+
Date.send(@method, 1582, -3, -27).should be_nil
|
32
|
+
Date.send(@method, 1582, -3, -22).should be_nil
|
33
|
+
Date.send(@method, 1582, -3, -21).should be_nil
|
34
|
+
Date.send(@method, 1582, -3, -18).should be_nil
|
35
|
+
Date.send(@method, 1582, -3, -17).should == Date.civil(1582, 10, 15).jd
|
36
|
+
|
37
|
+
Date.send(@method, 2007, -11, -10).should == Date.civil(2007, 2, 19).jd
|
38
|
+
Date.send(@method, 2008, -11, -10).should == Date.civil(2008, 2, 20).jd
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
ruby_version_is "1.9" do
|
43
|
+
it "returns true if it is a valid civil date" do
|
44
|
+
Date.send(@method, 1582, 10, 15).should be_true
|
45
|
+
Date.send(@method, 1582, 10, 14, Date::ENGLAND).should be_true
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns false if it is not a valid civil date" do
|
49
|
+
Date.send(@method, 1582, 10, 14).should == false
|
50
|
+
end
|
51
|
+
|
52
|
+
it "handles negative months and days" do
|
53
|
+
# October 1582 (the Gregorian calendar, Civil Date in 1.9)
|
54
|
+
# S M Tu W Th F S
|
55
|
+
# -21 -20 -19 -18 -17 -16
|
56
|
+
# -15 -14 -13 -12 -11 -10 -9
|
57
|
+
# -8 -7 -6 -5 -4 -3 -2
|
58
|
+
# -1
|
59
|
+
Date.send(@method, 1582, -3, -22).should be_false
|
60
|
+
Date.send(@method, 1582, -3, -21).should be_true
|
61
|
+
Date.send(@method, 1582, -3, -18).should be_true
|
62
|
+
Date.send(@method, 1582, -3, -17).should be_true
|
63
|
+
|
64
|
+
Date.send(@method, 2007, -11, -10).should be_true
|
65
|
+
Date.send(@method, 2008, -11, -10).should be_true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
describe :date_valid_commercial?, :shared => true do
|
2
|
+
ruby_version_is "" ... "1.9" do
|
3
|
+
it "returns the corresponding Julian Day Number if it is a valid commercial date" do
|
4
|
+
# October 1582 (the Gregorian calendar, Commercial Date in 1.8)
|
5
|
+
# M Tu W Th F Sa Su
|
6
|
+
# 41: - - - - 5 6 7
|
7
|
+
# 42: 1 2 3 4 5 6 7
|
8
|
+
# 43: 1 2 3 4 5 6 7
|
9
|
+
Date.send(@method, 1582, 41, 5).should == Date.civil(1582, 10, 15).jd
|
10
|
+
Date.send(@method, 1752, 37, 4, Date::ENGLAND).should == Date.civil(1752, 9, 14, Date::ENGLAND).jd
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns nil if it is not a valid commercial date" do
|
14
|
+
Date.send(@method, 1582, 41, 4).should be_nil
|
15
|
+
# valid_commercial? can't handle dates before the Gregorian calendar
|
16
|
+
Date.send(@method, 1582, 41, 4, Date::ENGLAND).should be_nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "handles negative week and day numbers" do
|
20
|
+
# October 1582 (the Gregorian calendar, Commercial Date in 1.8)
|
21
|
+
# M Tu W Th F Sa Su
|
22
|
+
# -12: - - - - -3 -2 -1
|
23
|
+
# -11: -7 -6 -5 -4 -3 -2 -1
|
24
|
+
# -10: -7 -6 -5 -4 -3 -2 -1
|
25
|
+
Date.send(@method, 1582, -12, -4).should be_nil
|
26
|
+
Date.send(@method, 1582, -12, -3).should == Date.civil(1582, 10, 15).jd
|
27
|
+
|
28
|
+
Date.send(@method, 2007, -44, -2).should == Date.civil(2007, 3, 3).jd
|
29
|
+
Date.send(@method, 2008, -44, -2).should == Date.civil(2008, 3, 1).jd
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
ruby_version_is "1.9" do
|
34
|
+
it "returns true if it is a valid commercial date" do
|
35
|
+
# October 1582 (the Gregorian calendar, Commercial Date in 1.9)
|
36
|
+
# M Tu W Th F Sa Su
|
37
|
+
# 39: 1 2 3 4 5 6 7
|
38
|
+
# 40: 1 2 3 4 5 6 7
|
39
|
+
# 41: 1 2 3 4 5 6 7
|
40
|
+
Date.send(@method, 1582, 39, 4).should be_true
|
41
|
+
Date.send(@method, 1582, 39, 5).should be_true
|
42
|
+
Date.send(@method, 1582, 41, 4).should be_true
|
43
|
+
Date.send(@method, 1582, 41, 5).should be_true
|
44
|
+
Date.send(@method, 1582, 41, 4, Date::ENGLAND).should be_true
|
45
|
+
Date.send(@method, 1752, 37, 4, Date::ENGLAND).should be_true
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns false it is not a valid commercial date" do
|
49
|
+
Date.send(@method, 1999, 53, 1).should be_false
|
50
|
+
end
|
51
|
+
|
52
|
+
it "handles negative week and day numbers" do
|
53
|
+
# October 1582 (the Gregorian calendar, Commercial Date in 1.9)
|
54
|
+
# M Tu W Th F Sa Su
|
55
|
+
# -12: -7 -6 -5 -4 -3 -2 -1
|
56
|
+
# -11: -7 -6 -5 -4 -3 -2 -1
|
57
|
+
# -10: -7 -6 -5 -4 -3 -2 -1
|
58
|
+
Date.send(@method, 1582, -12, -4).should be_true
|
59
|
+
Date.send(@method, 1582, -12, -3).should be_true
|
60
|
+
Date.send(@method, 2007, -44, -2).should be_true
|
61
|
+
Date.send(@method, 2008, -44, -2).should be_true
|
62
|
+
Date.send(@method, 1999, -53, -1).should be_false
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
describe :date_valid_jd?, :shared => true do
|
2
|
+
ruby_version_is "" ... "1.9" do
|
3
|
+
it "returns passed argument" do
|
4
|
+
Date.send(@method, -100).should == -100
|
5
|
+
Date.send(@method, :number).should == :number
|
6
|
+
Date.send(@method, nil).should == nil
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
ruby_version_is "1.9" do
|
12
|
+
it "returns true if passed any value other than nil" do
|
13
|
+
Date.send(@method, -100).should be_true
|
14
|
+
Date.send(@method, :number).should be_true
|
15
|
+
Date.send(@method, Rational(1,2)).should be_true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
ruby_version_is "1.9" do
|
20
|
+
it "returns false if passed nil" do
|
21
|
+
Date.send(@method, nil).should be_false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
ruby_version_is "1.9" ... "1.9.3" do
|
26
|
+
it "returns false if passed false" do
|
27
|
+
Date.send(@method, false).should be_false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
ruby_version_is "1.9.3" do
|
32
|
+
it "returns true if passed false" do
|
33
|
+
Date.send(@method, false).should be_true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
describe :date_valid_ordinal?, :shared => true do
|
2
|
+
ruby_version_is "" ... "1.9" do
|
3
|
+
it "determines if the date is a valid ordinal date" do
|
4
|
+
# October 1582 (the Gregorian calendar, Ordinal Date in 1.8)
|
5
|
+
# S M Tu W Th F S
|
6
|
+
# 274 275 276 277 278 279
|
7
|
+
# 280 281 282 283 284 285 286
|
8
|
+
# 287 288 289 290 291 292 293
|
9
|
+
# 294
|
10
|
+
Date.send(@method, 1582, 277).should == Date.civil(1582, 10, 4).jd
|
11
|
+
Date.send(@method, 1582, 278).should == nil
|
12
|
+
Date.send(@method, 1582, 287).should == nil
|
13
|
+
Date.send(@method, 1582, 288).should == Date.civil(1582, 10, 15).jd
|
14
|
+
Date.send(@method, 1582, 287, Date::ENGLAND).should_not == nil
|
15
|
+
Date.send(@method, 1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND).jd
|
16
|
+
end
|
17
|
+
|
18
|
+
it "handles negative day numbers" do
|
19
|
+
# October 1582 (the Gregorian calendar, Ordinal Date in 1.8)
|
20
|
+
# S M Tu W Th F S
|
21
|
+
# -92 -91 -90 -89 -78 -77
|
22
|
+
# -76 -75 -74 -73 -72 -71 -70
|
23
|
+
# -69 -68 -67 -66 -65 -64 -63
|
24
|
+
# -62
|
25
|
+
Date.send(@method, 1582, -89).should == Date.civil(1582, 10, 4).jd
|
26
|
+
Date.send(@method, 1582, -88).should == nil
|
27
|
+
Date.send(@method, 1582, -79).should == nil
|
28
|
+
Date.send(@method, 1582, -78).should == Date.civil(1582, 10, 15).jd
|
29
|
+
Date.send(@method, 2007, -100).should == Date.send(@method, 2007, 266)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
ruby_version_is "1.9" do
|
34
|
+
it "determines if the date is a valid ordinal date" do
|
35
|
+
# October 1582 (the Gregorian calendar, Ordinal Date in 1.9)
|
36
|
+
# S M Tu W Th F S
|
37
|
+
# 274 275 276 277 278 279
|
38
|
+
# 280 281 282 283 284 285 286
|
39
|
+
# 287 288 289 290 291 292 293
|
40
|
+
# 294
|
41
|
+
Date.send(@method, 1582, 277).should == true
|
42
|
+
Date.send(@method, 1582, 278).should == true
|
43
|
+
Date.send(@method, 1582, 287).should == true
|
44
|
+
Date.send(@method, 1582, 288).should == true
|
45
|
+
end
|
46
|
+
|
47
|
+
it "handles negative day numbers" do
|
48
|
+
# October 1582 (the Gregorian calendar, Ordinal Date in 1.9)
|
49
|
+
# S M Tu W Th F S
|
50
|
+
# -82 -81 -80 -79 -78 -77
|
51
|
+
# -76 -75 -74 -73 -72 -71 -70
|
52
|
+
# -69 -68 -67 -66 -65 -64 -63
|
53
|
+
# -62
|
54
|
+
Date.send(@method, 1582, -79).should == true
|
55
|
+
Date.send(@method, 1582, -78).should == true
|
56
|
+
Date.send(@method, 2007, -100).should == true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
describe "Date#step" do
|
4
|
+
|
5
|
+
it "steps forward in time" do
|
6
|
+
ds = Date.civil(2008, 10, 11)
|
7
|
+
de = Date.civil(2008, 9, 29)
|
8
|
+
count = 0
|
9
|
+
de.step(ds) do |d|
|
10
|
+
d.should <= ds
|
11
|
+
d.should >= de
|
12
|
+
count += 1
|
13
|
+
end
|
14
|
+
count.should == 13
|
15
|
+
|
16
|
+
count = 0
|
17
|
+
de.step(ds, 5) do |d|
|
18
|
+
d.should <= ds
|
19
|
+
d.should >= de
|
20
|
+
count += 1
|
21
|
+
end
|
22
|
+
count.should == 3
|
23
|
+
|
24
|
+
count = 0
|
25
|
+
ds.step(de) do |d|; count += 1; end
|
26
|
+
count.should == 0
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
it "steps backward in time" do
|
31
|
+
ds = Date.civil(2000, 4, 14)
|
32
|
+
de = Date.civil(2000, 3, 29)
|
33
|
+
count = 0
|
34
|
+
ds.step(de, -1) do |d|
|
35
|
+
d.should <= ds
|
36
|
+
d.should >= de
|
37
|
+
count += 1
|
38
|
+
end
|
39
|
+
count.should == 17
|
40
|
+
|
41
|
+
count = 0
|
42
|
+
ds.step(de, -5) do |d|
|
43
|
+
d.should <= ds
|
44
|
+
d.should >= de
|
45
|
+
count += 1
|
46
|
+
end
|
47
|
+
count.should == 4
|
48
|
+
|
49
|
+
count = 0
|
50
|
+
de.step(ds, -1) do |d|; count += 1; end
|
51
|
+
count.should == 0
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|