smart_month 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README +33 -0
  3. data/Rakefile +51 -0
  4. data/VERSION +1 -0
  5. data/lib/month.rb +26 -0
  6. data/lib/smart_month.rb +11 -0
  7. data/lib/smart_month/calculations.rb +87 -0
  8. data/lib/smart_month/collection.rb +51 -0
  9. data/lib/smart_month/extensions/date.rb +19 -0
  10. data/lib/smart_month/magic.rb +71 -0
  11. data/lib/smart_month/math.rb +41 -0
  12. data/lib/smart_month/rulesets.rb +151 -0
  13. data/lib/smart_month/util.rb +37 -0
  14. data/pkg/smart_month-1.0.0.gem +0 -0
  15. data/rdoc/classes/Date.html +209 -0
  16. data/rdoc/classes/Month.html +189 -0
  17. data/rdoc/classes/SmartMonth.html +136 -0
  18. data/rdoc/classes/SmartMonth/Calculations.html +383 -0
  19. data/rdoc/classes/SmartMonth/Collection.html +306 -0
  20. data/rdoc/classes/SmartMonth/Magic.html +214 -0
  21. data/rdoc/classes/SmartMonth/Magic/MonthFactory.html +178 -0
  22. data/rdoc/classes/SmartMonth/Math.html +311 -0
  23. data/rdoc/classes/SmartMonth/Rulesets.html +419 -0
  24. data/rdoc/classes/SmartMonth/Util.html +302 -0
  25. data/rdoc/classes/Time.html +152 -0
  26. data/rdoc/created.rid +1 -0
  27. data/rdoc/files/README.html +170 -0
  28. data/rdoc/files/lib/month_rb.html +113 -0
  29. data/rdoc/files/lib/smart_month/calculations_rb.html +101 -0
  30. data/rdoc/files/lib/smart_month/collection_rb.html +101 -0
  31. data/rdoc/files/lib/smart_month/extensions/date_rb.html +108 -0
  32. data/rdoc/files/lib/smart_month/magic_rb.html +101 -0
  33. data/rdoc/files/lib/smart_month/math_rb.html +101 -0
  34. data/rdoc/files/lib/smart_month/rulesets_rb.html +108 -0
  35. data/rdoc/files/lib/smart_month/util_rb.html +101 -0
  36. data/rdoc/files/lib/smart_month_rb.html +108 -0
  37. data/rdoc/fr_class_index.html +37 -0
  38. data/rdoc/fr_file_index.html +36 -0
  39. data/rdoc/fr_method_index.html +74 -0
  40. data/rdoc/index.html +24 -0
  41. data/rdoc/rdoc-style.css +208 -0
  42. data/smart_month.gemspec +179 -0
  43. data/test/spec/date/accessor_spec.rb +91 -0
  44. data/test/spec/date/add_month_spec.rb +24 -0
  45. data/test/spec/date/add_spec.rb +23 -0
  46. data/test/spec/date/boat_spec.rb +20 -0
  47. data/test/spec/date/civil_spec.rb +28 -0
  48. data/test/spec/date/commercial_spec.rb +29 -0
  49. data/test/spec/date/constants_spec.rb +41 -0
  50. data/test/spec/date/conversions_spec.rb +153 -0
  51. data/test/spec/date/downto_spec.rb +18 -0
  52. data/test/spec/date/eql_spec.rb +10 -0
  53. data/test/spec/date/gregorian_spec.rb +28 -0
  54. data/test/spec/date/hash_spec.rb +14 -0
  55. data/test/spec/date/infinity_spec.rb +77 -0
  56. data/test/spec/date/julian_spec.rb +52 -0
  57. data/test/spec/date/minus_month_spec.rb +23 -0
  58. data/test/spec/date/minus_spec.rb +30 -0
  59. data/test/spec/date/new_spec.rb +9 -0
  60. data/test/spec/date/neww_spec.rb +9 -0
  61. data/test/spec/date/ordinal_spec.rb +29 -0
  62. data/test/spec/date/parse_spec.rb +149 -0
  63. data/test/spec/date/relationship_spec.rb +20 -0
  64. data/test/spec/date/shared/civil.rb +66 -0
  65. data/test/spec/date/shared/commercial.rb +39 -0
  66. data/test/spec/date/shared/parse.rb +54 -0
  67. data/test/spec/date/shared/parse_eu.rb +30 -0
  68. data/test/spec/date/shared/parse_us.rb +29 -0
  69. data/test/spec/date/step_spec.rb +56 -0
  70. data/test/spec/date/strftime_spec.rb +205 -0
  71. data/test/spec/date/strptime_spec.rb +143 -0
  72. data/test/spec/date/upto_spec.rb +18 -0
  73. data/test/spec/parsedate/parsedate.rb +95 -0
  74. data/test/spec/time/httpdate_spec.rb +21 -0
  75. data/test/spec/time/iso8601_spec.rb +7 -0
  76. data/test/spec/time/rfc2822_spec.rb +7 -0
  77. data/test/spec/time/rfc822_spec.rb +7 -0
  78. data/test/spec/time/shared/rfc2822.rb +65 -0
  79. data/test/spec/time/shared/xmlschema.rb +53 -0
  80. data/test/spec/time/xmlschema_spec.rb +7 -0
  81. data/test/spec_helper.rb +56 -0
  82. data/test/test_helper.rb +4 -0
  83. data/test/unit/calculations_test.rb +82 -0
  84. data/test/unit/collection_test.rb +42 -0
  85. data/test/unit/magic_test.rb +37 -0
  86. data/test/unit/math_test.rb +30 -0
  87. data/test/unit/rulesets_test.rb +94 -0
  88. data/test/unit/samples/test_ruleset.yml +6 -0
  89. data/test/unit/util_test.rb +29 -0
  90. metadata +196 -0
@@ -0,0 +1,179 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{smart_month}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Derek Perez", "Jonathan Silverman"]
12
+ s.date = %q{2010-01-06}
13
+ s.description = %q{You can use SmartMonth to:
14
+ - Determine the first tuesday of any month in any year.
15
+ - Determine all of the fridays of any month in any year.
16
+ - Iterate through all the days of a month.
17
+ - Determine how many days of the month there are.
18
+ - Determine the first and last days of the month.
19
+ - And other fun date/month related things!}
20
+ s.email = %q{derek@derekperez.com}
21
+ s.extra_rdoc_files = [
22
+ "README"
23
+ ]
24
+ s.files = [
25
+ "MIT-LICENSE",
26
+ "README",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/month.rb",
30
+ "lib/smart_month.rb",
31
+ "lib/smart_month/calculations.rb",
32
+ "lib/smart_month/collection.rb",
33
+ "lib/smart_month/extensions/date.rb",
34
+ "lib/smart_month/magic.rb",
35
+ "lib/smart_month/math.rb",
36
+ "lib/smart_month/rulesets.rb",
37
+ "lib/smart_month/util.rb",
38
+ "pkg/smart_month-1.0.0.gem",
39
+ "rdoc/classes/Date.html",
40
+ "rdoc/classes/Month.html",
41
+ "rdoc/classes/SmartMonth.html",
42
+ "rdoc/classes/SmartMonth/Calculations.html",
43
+ "rdoc/classes/SmartMonth/Collection.html",
44
+ "rdoc/classes/SmartMonth/Magic.html",
45
+ "rdoc/classes/SmartMonth/Magic/MonthFactory.html",
46
+ "rdoc/classes/SmartMonth/Math.html",
47
+ "rdoc/classes/SmartMonth/Rulesets.html",
48
+ "rdoc/classes/SmartMonth/Util.html",
49
+ "rdoc/classes/Time.html",
50
+ "rdoc/created.rid",
51
+ "rdoc/files/README.html",
52
+ "rdoc/files/lib/month_rb.html",
53
+ "rdoc/files/lib/smart_month/calculations_rb.html",
54
+ "rdoc/files/lib/smart_month/collection_rb.html",
55
+ "rdoc/files/lib/smart_month/extensions/date_rb.html",
56
+ "rdoc/files/lib/smart_month/magic_rb.html",
57
+ "rdoc/files/lib/smart_month/math_rb.html",
58
+ "rdoc/files/lib/smart_month/rulesets_rb.html",
59
+ "rdoc/files/lib/smart_month/util_rb.html",
60
+ "rdoc/files/lib/smart_month_rb.html",
61
+ "rdoc/fr_class_index.html",
62
+ "rdoc/fr_file_index.html",
63
+ "rdoc/fr_method_index.html",
64
+ "rdoc/index.html",
65
+ "rdoc/rdoc-style.css",
66
+ "smart_month.gemspec",
67
+ "test/spec/date/accessor_spec.rb",
68
+ "test/spec/date/add_month_spec.rb",
69
+ "test/spec/date/add_spec.rb",
70
+ "test/spec/date/boat_spec.rb",
71
+ "test/spec/date/civil_spec.rb",
72
+ "test/spec/date/commercial_spec.rb",
73
+ "test/spec/date/constants_spec.rb",
74
+ "test/spec/date/conversions_spec.rb",
75
+ "test/spec/date/downto_spec.rb",
76
+ "test/spec/date/eql_spec.rb",
77
+ "test/spec/date/gregorian_spec.rb",
78
+ "test/spec/date/hash_spec.rb",
79
+ "test/spec/date/infinity_spec.rb",
80
+ "test/spec/date/julian_spec.rb",
81
+ "test/spec/date/minus_month_spec.rb",
82
+ "test/spec/date/minus_spec.rb",
83
+ "test/spec/date/new_spec.rb",
84
+ "test/spec/date/neww_spec.rb",
85
+ "test/spec/date/ordinal_spec.rb",
86
+ "test/spec/date/parse_spec.rb",
87
+ "test/spec/date/relationship_spec.rb",
88
+ "test/spec/date/shared/civil.rb",
89
+ "test/spec/date/shared/commercial.rb",
90
+ "test/spec/date/shared/parse.rb",
91
+ "test/spec/date/shared/parse_eu.rb",
92
+ "test/spec/date/shared/parse_us.rb",
93
+ "test/spec/date/step_spec.rb",
94
+ "test/spec/date/strftime_spec.rb",
95
+ "test/spec/date/strptime_spec.rb",
96
+ "test/spec/date/upto_spec.rb",
97
+ "test/spec/parsedate/parsedate.rb",
98
+ "test/spec/time/httpdate_spec.rb",
99
+ "test/spec/time/iso8601_spec.rb",
100
+ "test/spec/time/rfc2822_spec.rb",
101
+ "test/spec/time/rfc822_spec.rb",
102
+ "test/spec/time/shared/rfc2822.rb",
103
+ "test/spec/time/shared/xmlschema.rb",
104
+ "test/spec/time/xmlschema_spec.rb",
105
+ "test/spec_helper.rb",
106
+ "test/test_helper.rb",
107
+ "test/unit/calculations_test.rb",
108
+ "test/unit/collection_test.rb",
109
+ "test/unit/magic_test.rb",
110
+ "test/unit/math_test.rb",
111
+ "test/unit/rulesets_test.rb",
112
+ "test/unit/samples/test_ruleset.yml",
113
+ "test/unit/util_test.rb"
114
+ ]
115
+ s.homepage = %q{http://github.com/perezd/smart_month}
116
+ s.rdoc_options = ["--charset=UTF-8"]
117
+ s.require_paths = ["lib"]
118
+ s.rubygems_version = %q{1.3.5}
119
+ s.summary = %q{SmartMonth is a "bodysnatcher" plugin that takes boring Date month fixnums and replaces them with a rich toolkit of functionality.}
120
+ s.test_files = [
121
+ "test/test_helper.rb",
122
+ "test/spec/date/strftime_spec.rb",
123
+ "test/spec/date/ordinal_spec.rb",
124
+ "test/spec/date/step_spec.rb",
125
+ "test/spec/date/hash_spec.rb",
126
+ "test/spec/date/new_spec.rb",
127
+ "test/spec/date/relationship_spec.rb",
128
+ "test/spec/date/julian_spec.rb",
129
+ "test/spec/date/shared/parse.rb",
130
+ "test/spec/date/shared/civil.rb",
131
+ "test/spec/date/shared/parse_eu.rb",
132
+ "test/spec/date/shared/parse_us.rb",
133
+ "test/spec/date/shared/commercial.rb",
134
+ "test/spec/date/strptime_spec.rb",
135
+ "test/spec/date/neww_spec.rb",
136
+ "test/spec/date/add_month_spec.rb",
137
+ "test/spec/date/add_spec.rb",
138
+ "test/spec/date/minus_spec.rb",
139
+ "test/spec/date/civil_spec.rb",
140
+ "test/spec/date/minus_month_spec.rb",
141
+ "test/spec/date/commercial_spec.rb",
142
+ "test/spec/date/parse_spec.rb",
143
+ "test/spec/date/gregorian_spec.rb",
144
+ "test/spec/date/downto_spec.rb",
145
+ "test/spec/date/accessor_spec.rb",
146
+ "test/spec/date/upto_spec.rb",
147
+ "test/spec/date/infinity_spec.rb",
148
+ "test/spec/date/boat_spec.rb",
149
+ "test/spec/date/eql_spec.rb",
150
+ "test/spec/date/constants_spec.rb",
151
+ "test/spec/date/conversions_spec.rb",
152
+ "test/spec/parsedate/parsedate.rb",
153
+ "test/spec/time/shared/rfc2822.rb",
154
+ "test/spec/time/shared/xmlschema.rb",
155
+ "test/spec/time/httpdate_spec.rb",
156
+ "test/spec/time/rfc2822_spec.rb",
157
+ "test/spec/time/iso8601_spec.rb",
158
+ "test/spec/time/xmlschema_spec.rb",
159
+ "test/spec/time/rfc822_spec.rb",
160
+ "test/unit/util_test.rb",
161
+ "test/unit/calculations_test.rb",
162
+ "test/unit/collection_test.rb",
163
+ "test/unit/math_test.rb",
164
+ "test/unit/rulesets_test.rb",
165
+ "test/unit/magic_test.rb",
166
+ "test/spec_helper.rb"
167
+ ]
168
+
169
+ if s.respond_to? :specification_version then
170
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
171
+ s.specification_version = 3
172
+
173
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
174
+ else
175
+ end
176
+ else
177
+ end
178
+ end
179
+
@@ -0,0 +1,91 @@
1
+ require 'date'
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
+
4
+ describe "Date#ajd" do
5
+ it "should be able to determine the Astronomical Julian day for a date" do
6
+ Date.civil(2007, 1, 17).ajd.should == 4908235.to_r / 2
7
+ end
8
+ end
9
+
10
+ describe "Date#amjd" do
11
+ it "should be able to determine the Astronomical Modified Julian day for a date" do
12
+ Date.civil(2007, 1, 17).amjd.should == 54117
13
+ end
14
+ end
15
+
16
+ describe "Date#day_fraction" do
17
+ it "should be able to determine the day fraction for a date" do
18
+ Date.civil(2007, 1, 17).day_fraction.should == 0
19
+ end
20
+ end
21
+
22
+ describe "Date#mjd" do
23
+ it "should be able to determine the Modified Julian day for a date" do
24
+ Date.civil(2007, 1, 17).mjd.should == 54117
25
+ end
26
+ end
27
+
28
+ describe "Date#ld" do
29
+ it "should be able to determine the Modified Julian day for a date" do
30
+ Date.civil(2007, 1, 17).ld.should == 154958
31
+ end
32
+ end
33
+
34
+ describe "Date#year" do
35
+ it "should be able to determine the year for a date" do
36
+ Date.civil(2007, 1, 17).year.should == 2007
37
+ end
38
+ end
39
+
40
+ describe "Date#yday" do
41
+ it "should be able to determine the year for a date" do
42
+ Date.civil(2007, 1, 17).yday.should == 17
43
+ Date.civil(2008, 10, 28).yday.should == 302
44
+ end
45
+ end
46
+
47
+ describe "Date#mon" do
48
+ it "should be able to determine the month for a date" do
49
+ Date.civil(2007, 1, 17).mon.should == 1
50
+ Date.civil(2008, 10, 28).mon.should == 10
51
+ end
52
+ end
53
+
54
+ describe "Date#mday" do
55
+ it "should be able to determine the day of the month for a date" do
56
+ Date.civil(2007, 1, 17).mday.should == 17
57
+ Date.civil(2008, 10, 28).mday.should == 28
58
+ end
59
+ end
60
+
61
+ describe "Date#wday" do
62
+ it "should be able to determine the week day for a date" do
63
+ Date.civil(2007, 1, 17).wday.should == 3
64
+ Date.civil(2008, 10, 26).wday.should == 0
65
+ end
66
+ end
67
+
68
+ describe "Date#cwyear" do
69
+ it "should be able to determine the commercial year for a date" do
70
+ Date.civil(2007, 1, 17).cwyear.should == 2007
71
+ Date.civil(2008, 10, 28).cwyear.should == 2008
72
+ Date.civil(2007, 12, 31).cwyear.should == 2008
73
+ Date.civil(2010, 1, 1).cwyear.should == 2009
74
+ end
75
+ end
76
+
77
+ describe "Date#cweek" do
78
+ it "should be able to determine the commercial week for a date" do
79
+ Date.civil(2007, 1, 17).cweek.should == 3
80
+ Date.civil(2008, 10, 28).cweek.should == 44
81
+ Date.civil(2007, 12, 31).cweek.should == 1
82
+ Date.civil(2010, 1, 1).cweek.should == 53
83
+ end
84
+ end
85
+
86
+ describe "Date#cwday" do
87
+ it "should be able to determine the commercial week day for a date" do
88
+ Date.civil(2007, 1, 17).cwday.should == 3
89
+ Date.civil(2008, 10, 26).cwday.should == 7
90
+ end
91
+ end
@@ -0,0 +1,24 @@
1
+ require 'date'
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
+
4
+ describe "Date#>>" do
5
+
6
+ it "should add a number of months to a Date" do
7
+ d = Date.civil(2007,2,27) >> 10
8
+ d.should == Date.civil(2007, 12, 27)
9
+ end
10
+
11
+
12
+ it "should result in the last day of a month if the day doesn't exist" do
13
+ d = Date.civil(2008,3,31) >> 1
14
+ d.should == Date.civil(2008, 4, 30)
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) >> "hello" }.should raise_error(TypeError)
20
+ lambda { Date.civil(2007,2,27) >> Date.new }.should raise_error(TypeError)
21
+ lambda { Date.civil(2007,2,27) >> Object.new }.should raise_error(TypeError)
22
+ end
23
+
24
+ end
@@ -0,0 +1,23 @@
1
+ require 'date'
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
+
4
+ describe "Date#+" do
5
+
6
+ it "should add a number of days to a Date" do
7
+ d = Date.civil(2007,2,27) + 10
8
+ d.should == Date.civil(2007, 3, 9)
9
+ end
10
+
11
+ it "should add a negative number of days to a Date" do
12
+ d = Date.civil(2007,2,27).+(-10)
13
+ d.should == Date.civil(2007, 2, 17)
14
+ end
15
+
16
+ it "should raise an error on non numeric parameters" do
17
+ lambda { Date.civil(2007,2,27) + :hello }.should raise_error(TypeError)
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,20 @@
1
+ require 'date'
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
+
4
+ describe "Date#<=>" do
5
+
6
+ it "should be able to compare two same dates" do
7
+ (Date.civil(2000, 04, 06) <=> Date.civil(2000, 04, 06)).should == 0
8
+ end
9
+
10
+ it "should be able to compute the difference between two dates" do
11
+ (Date.civil(2000, 04, 05) <=> Date.civil(2000, 04, 06)).should == -1
12
+ (Date.civil(2001, 04, 05) <=> Date.civil(2000, 04, 06)).should == 1
13
+ end
14
+
15
+ it "should be able to compare to another numeric" do
16
+ (Date.civil(2000, 04, 05) <=> Date.civil(2000, 04, 06).jd).should == -1
17
+ (Date.civil(2001, 04, 05) <=> Date.civil(2000, 04, 06).jd).should == 1
18
+ end
19
+
20
+ end
@@ -0,0 +1,28 @@
1
+ require 'date'
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.dirname(__FILE__) + '/shared/civil'
4
+
5
+ describe "Date#civil" do
6
+
7
+ it_behaves_like(:date_civil, :civil)
8
+
9
+ end
10
+
11
+ describe "Date#valid_civil?" do
12
+
13
+ it "should be able to determine if a date is valid" do
14
+ Date.valid_civil?(1582, 10, 14).should == nil
15
+ Date.valid_civil?(1582, 10, 15).should == Date.civil(1582, 10, 15).jd
16
+ Date.valid_civil?(1582, 10, 14, Date::ENGLAND).should_not == nil
17
+ Date.valid_civil?(1582, 10, 14, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND).jd
18
+ end
19
+
20
+ it "should be able to handle negative months and days" do
21
+ Date.valid_civil?(1582, -3, -18).should == nil
22
+ Date.valid_civil?(1582, -3, -17).should == Date.civil(1582, 10, 15).jd
23
+
24
+ Date.valid_civil?(2007, -11, -10).should == Date.civil(2007, 2, 19).jd
25
+ Date.valid_civil?(2008, -11, -10).should == Date.civil(2008, 2, 20).jd
26
+ end
27
+
28
+ end
@@ -0,0 +1,29 @@
1
+ require 'date'
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
+ require File.dirname(__FILE__) + '/shared/commercial'
4
+
5
+ describe "Date#commercial" do
6
+
7
+ it_behaves_like(:date_commercial, :commercial)
8
+
9
+ end
10
+
11
+ describe "Date#valid_commercial?" do
12
+
13
+ it "should be able to determine if the date is a valid commercial date" do
14
+ Date.valid_commercial?(1582, 41, 4).should == nil
15
+ Date.valid_commercial?(1582, 41, 5).should == Date.civil(1582, 10, 15).jd
16
+ # valid_commercial? can't handle dates before the Gregorian calendar
17
+ Date.valid_commercial?(1582, 41, 4, Date::ENGLAND).should == nil
18
+ Date.valid_commercial?(1752, 37, 4, Date::ENGLAND).should == Date.civil(1752, 9, 14, Date::ENGLAND).jd
19
+ end
20
+
21
+ it "should be able to handle negative week and day numbers" do
22
+ Date.valid_commercial?(1582, -12, -4).should == nil
23
+ Date.valid_commercial?(1582, -12, -3).should == Date.civil(1582, 10, 15).jd
24
+
25
+ Date.valid_commercial?(2007, -44, -2).should == Date.civil(2007, 3, 3).jd
26
+ Date.valid_commercial?(2008, -44, -2).should == Date.civil(2008, 3, 1).jd
27
+ end
28
+
29
+ end
@@ -0,0 +1,41 @@
1
+ require 'date'
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
+
4
+ describe "Date constants" do
5
+
6
+ it "should define ITALY" do
7
+ Date::ITALY.should == 2299161 # 1582-10-15
8
+ end
9
+
10
+ it "should define ENGLAND" do
11
+ Date::ENGLAND.should == 2361222 # 1752-09-14
12
+ end
13
+
14
+ # Fixes in 1.8.7
15
+ ruby_bug "#", "1.8.6" do
16
+ it "should define JULIAN" do
17
+ (Date::JULIAN <=> Date::Infinity.new).should == 0
18
+ end
19
+ end
20
+
21
+ # Fixed in 1.8.7
22
+ ruby_bug "#", "1.8.6" do
23
+ it "should define GREGORIAN" do
24
+ (Date::GREGORIAN <=> -Date::Infinity.new).should == 0
25
+ end
26
+ end
27
+
28
+ it "should define MONTHNAMES" do
29
+ Date::MONTHNAMES.should == [nil] + %w(January February March April May June July
30
+ August September October November December)
31
+ end
32
+
33
+ it "should define DAYNAMES" do
34
+ Date::DAYNAMES.should == %w(Sunday Monday Tuesday Wednesday Thursday Friday Saturday)
35
+ end
36
+
37
+ it "should define ABBR_MONTHNAMES" do
38
+ Date::ABBR_DAYNAMES.should == %w(Sun Mon Tue Wed Thu Fri Sat)
39
+ end
40
+
41
+ end
@@ -0,0 +1,153 @@
1
+ require 'date'
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
+
4
+
5
+ describe "Date#new_start" do
6
+ it "should convert a date object into another with a new calendar reform" do
7
+ Date.civil(1582, 10, 14, Date::ENGLAND).new_start.should == Date.civil(1582, 10, 24)
8
+ Date.civil(1582, 10, 4, Date::ENGLAND).new_start.should == Date.civil(1582, 10, 4)
9
+ Date.civil(1582, 10, 15).new_start(Date::ENGLAND).should == Date.civil(1582, 10, 5, Date::ENGLAND)
10
+ Date.civil(1752, 9, 14).new_start(Date::ENGLAND).should == Date.civil(1752, 9, 14, Date::ENGLAND)
11
+ Date.civil(1752, 9, 13).new_start(Date::ENGLAND).should == Date.civil(1752, 9, 2, Date::ENGLAND)
12
+ end
13
+ end
14
+
15
+ describe "Date#italy" do
16
+ it "should convert a date object into another with the Italian calendar reform" do
17
+ Date.civil(1582, 10, 14, Date::ENGLAND).italy.should == Date.civil(1582, 10, 24)
18
+ Date.civil(1582, 10, 4, Date::ENGLAND).italy.should == Date.civil(1582, 10, 4)
19
+ end
20
+ end
21
+
22
+ describe "Date#england" do
23
+ it "should convert a date object into another with the English calendar reform" do
24
+ Date.civil(1582, 10, 15).england.should == Date.civil(1582, 10, 5, Date::ENGLAND)
25
+ Date.civil(1752, 9, 14).england.should == Date.civil(1752, 9, 14, Date::ENGLAND)
26
+ Date.civil(1752, 9, 13).england.should == Date.civil(1752, 9, 2, Date::ENGLAND)
27
+ end
28
+ end
29
+
30
+ describe "Date#julian" do
31
+ it "should convert a date object into another with the Julian calendar" do
32
+ Date.civil(1582, 10, 15).julian.should == Date.civil(1582, 10, 5, Date::JULIAN)
33
+ Date.civil(1752, 9, 14).julian.should == Date.civil(1752, 9, 3, Date::JULIAN)
34
+ Date.civil(1752, 9, 13).julian.should == Date.civil(1752, 9, 2, Date::JULIAN)
35
+ end
36
+ end
37
+
38
+ describe "Date#gregorian" do
39
+ it "should convert a date object into another with the Gregorian calendar" do
40
+ Date.civil(1582, 10, 4).gregorian.should == Date.civil(1582, 10, 14, Date::GREGORIAN)
41
+ Date.civil(1752, 9, 14).gregorian.should == Date.civil(1752, 9, 14, Date::GREGORIAN)
42
+ end
43
+ end
44
+
45
+ describe "Date#ordinal_to_jd" do
46
+ it "should convert an ordinal date (year-day) to a Julian day number" do
47
+ Date.ordinal_to_jd(2007, 55).should == 2454156
48
+ end
49
+ end
50
+
51
+ describe "Date#jd_to_ordinal" do
52
+ it "should convert a Julian day number into an ordinal date" do
53
+ Date.jd_to_ordinal(2454156).should == [2007, 55]
54
+ end
55
+ end
56
+
57
+ describe "Date#civil_to_jd" do
58
+ it "should convert a civil date into a Julian day number" do
59
+ Date.civil_to_jd(2007, 2, 24).should == 2454156
60
+ end
61
+ end
62
+
63
+ describe "Date#jd_to_civil" do
64
+ it "should convert a Julian day into a civil date" do
65
+ Date.jd_to_civil(2454156).should == [2007, 2, 24]
66
+ end
67
+ end
68
+
69
+ describe "Date#commercial_to_jd" do
70
+ it "should convert a commercial date (year - week - day of week) into a Julian day number" do
71
+ Date.commercial_to_jd(2007, 45, 1).should == 2454410
72
+ end
73
+ end
74
+
75
+ describe "Date#jd_to_commercial" do
76
+ it "should convert a Julian day number into a commercial date" do
77
+ Date.jd_to_commercial(2454410).should == [2007, 45, 1]
78
+ end
79
+ end
80
+
81
+ describe "Date#ajd_to_jd" do
82
+ it "should convert a Astronomical Julian day number into a Julian day number" do
83
+ Date.ajd_to_jd(2454410).should == [2454410, Rational(1,2)]
84
+ Date.ajd_to_jd(2454410, 1.to_r / 2).should == [2454411, 0]
85
+ end
86
+ end
87
+
88
+ describe "Date#jd_to_ajd" do
89
+ it "should convert a Julian day number into a Astronomical Julian day number" do
90
+ Date.jd_to_ajd(2454410, 0).should == 2454410 - Rational(1, 2)
91
+ Date.jd_to_ajd(2454410, 1.to_r / 2).should == 2454410
92
+ end
93
+ end
94
+
95
+ describe "Date#day_fraction_to_time" do
96
+ it "should be able to convert a day fraction into time" do
97
+ Date.day_fraction_to_time(2).should == [48, 0, 0, 0]
98
+ Date.day_fraction_to_time(1).should == [24, 0, 0, 0]
99
+ Date.day_fraction_to_time(1.to_r / 2).should == [12, 0, 0, 0]
100
+ Date.day_fraction_to_time(1.to_r / 7).should == [3, 25, 42, 1.to_r / 100800]
101
+ end
102
+ end
103
+
104
+ describe "Date#time_to_day_fraction" do
105
+ it "should be able to convert a time into a day fraction" do
106
+ Date.time_to_day_fraction(48, 0, 0).should == 2
107
+ Date.time_to_day_fraction(24, 0, 0).should == 1
108
+ Date.time_to_day_fraction(12, 0, 0).should == 1.to_r / 2
109
+ Date.time_to_day_fraction(10, 20, 10).should == 10.to_r / 24 + 20.to_r / (24 * 60) + 10.to_r / (24 * 60 * 60)
110
+ end
111
+ end
112
+
113
+ describe "Date#amjd_to_ajd" do
114
+ it "shoud be able to convert Astronomical Modified Julian day numbers into Astronomical Julian day numbers" do
115
+ Date.amjd_to_ajd(10).should == 10 + 2400000 + 1.to_r / 2
116
+ end
117
+ end
118
+
119
+ describe "Date#ajd_to_amjd" do
120
+ it "shoud be able to convert Astronomical Julian day numbers into Astronomical Modified Julian day numbers" do
121
+ Date.ajd_to_amjd(10000010).should == 10000010 - 2400000 - 1.to_r / 2
122
+ end
123
+ end
124
+
125
+ describe "Date#mjd_to_jd" do
126
+ it "shoud be able to convert Modified Julian day numbers into Julian day numbers" do
127
+ Date.mjd_to_jd(2000).should == 2000 + 2400001
128
+ end
129
+ end
130
+
131
+ describe "Date#jd_to_mjd" do
132
+ it "shoud be able to convert Julian day numbers into Modified Julian day numbers" do
133
+ Date.jd_to_mjd(2500000).should == 2500000 - 2400001
134
+ end
135
+ end
136
+
137
+ describe "Date#ld_to_jd" do
138
+ it "should be able to convert the number of days since the Gregorian calendar in Italy into Julian day numbers" do
139
+ Date.ld_to_jd(450000).should == 450000 + 2299160
140
+ end
141
+ end
142
+
143
+ describe "Date#jd_to_ld" do
144
+ it "should be able to convert Julian day numbers into the number of days since the Gregorian calendar in Italy" do
145
+ Date.jd_to_ld(2450000).should == 2450000 - 2299160
146
+ end
147
+ end
148
+
149
+ describe "Date#jd_to_wday" do
150
+ it "should be able to convert a Julian day number into a week day number" do
151
+ Date.jd_to_wday(2454482).should == 3
152
+ end
153
+ end