anniversary 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,208 @@
1
+
2
+ body {
3
+ font-family: Verdana,Arial,Helvetica,sans-serif;
4
+ font-size: 90%;
5
+ margin: 0;
6
+ margin-left: 40px;
7
+ padding: 0;
8
+ background: white;
9
+ }
10
+
11
+ h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; }
12
+ h1 { font-size: 150%; }
13
+ h2,h3,h4 { margin-top: 1em; }
14
+
15
+ a { background: #eef; color: #039; text-decoration: none; }
16
+ a:hover { background: #039; color: #eef; }
17
+
18
+ /* Override the base stylesheet's Anchor inside a table cell */
19
+ td > a {
20
+ background: transparent;
21
+ color: #039;
22
+ text-decoration: none;
23
+ }
24
+
25
+ /* and inside a section title */
26
+ .section-title > a {
27
+ background: transparent;
28
+ color: #eee;
29
+ text-decoration: none;
30
+ }
31
+
32
+ /* === Structural elements =================================== */
33
+
34
+ div#index {
35
+ margin: 0;
36
+ margin-left: -40px;
37
+ padding: 0;
38
+ font-size: 90%;
39
+ }
40
+
41
+
42
+ div#index a {
43
+ margin-left: 0.7em;
44
+ }
45
+
46
+ div#index .section-bar {
47
+ margin-left: 0px;
48
+ padding-left: 0.7em;
49
+ background: #ccc;
50
+ font-size: small;
51
+ }
52
+
53
+
54
+ div#classHeader, div#fileHeader {
55
+ width: auto;
56
+ color: white;
57
+ padding: 0.5em 1.5em 0.5em 1.5em;
58
+ margin: 0;
59
+ margin-left: -40px;
60
+ border-bottom: 3px solid #006;
61
+ }
62
+
63
+ div#classHeader a, div#fileHeader a {
64
+ background: inherit;
65
+ color: white;
66
+ }
67
+
68
+ div#classHeader td, div#fileHeader td {
69
+ background: inherit;
70
+ color: white;
71
+ }
72
+
73
+
74
+ div#fileHeader {
75
+ background: #057;
76
+ }
77
+
78
+ div#classHeader {
79
+ background: #048;
80
+ }
81
+
82
+
83
+ .class-name-in-header {
84
+ font-size: 180%;
85
+ font-weight: bold;
86
+ }
87
+
88
+
89
+ div#bodyContent {
90
+ padding: 0 1.5em 0 1.5em;
91
+ }
92
+
93
+ div#description {
94
+ padding: 0.5em 1.5em;
95
+ background: #efefef;
96
+ border: 1px dotted #999;
97
+ }
98
+
99
+ div#description h1,h2,h3,h4,h5,h6 {
100
+ color: #125;;
101
+ background: transparent;
102
+ }
103
+
104
+ div#validator-badges {
105
+ text-align: center;
106
+ }
107
+ div#validator-badges img { border: 0; }
108
+
109
+ div#copyright {
110
+ color: #333;
111
+ background: #efefef;
112
+ font: 0.75em sans-serif;
113
+ margin-top: 5em;
114
+ margin-bottom: 0;
115
+ padding: 0.5em 2em;
116
+ }
117
+
118
+
119
+ /* === Classes =================================== */
120
+
121
+ table.header-table {
122
+ color: white;
123
+ font-size: small;
124
+ }
125
+
126
+ .type-note {
127
+ font-size: small;
128
+ color: #DEDEDE;
129
+ }
130
+
131
+ .xxsection-bar {
132
+ background: #eee;
133
+ color: #333;
134
+ padding: 3px;
135
+ }
136
+
137
+ .section-bar {
138
+ color: #333;
139
+ border-bottom: 1px solid #999;
140
+ margin-left: -20px;
141
+ }
142
+
143
+
144
+ .section-title {
145
+ background: #79a;
146
+ color: #eee;
147
+ padding: 3px;
148
+ margin-top: 2em;
149
+ margin-left: -30px;
150
+ border: 1px solid #999;
151
+ }
152
+
153
+ .top-aligned-row { vertical-align: top }
154
+ .bottom-aligned-row { vertical-align: bottom }
155
+
156
+ /* --- Context section classes ----------------------- */
157
+
158
+ .context-row { }
159
+ .context-item-name { font-family: monospace; font-weight: bold; color: black; }
160
+ .context-item-value { font-size: small; color: #448; }
161
+ .context-item-desc { color: #333; padding-left: 2em; }
162
+
163
+ /* --- Method classes -------------------------- */
164
+ .method-detail {
165
+ background: #efefef;
166
+ padding: 0;
167
+ margin-top: 0.5em;
168
+ margin-bottom: 1em;
169
+ border: 1px dotted #ccc;
170
+ }
171
+ .method-heading {
172
+ color: black;
173
+ background: #ccc;
174
+ border-bottom: 1px solid #666;
175
+ padding: 0.2em 0.5em 0 0.5em;
176
+ }
177
+ .method-signature { color: black; background: inherit; }
178
+ .method-name { font-weight: bold; }
179
+ .method-args { font-style: italic; }
180
+ .method-description { padding: 0 0.5em 0 0.5em; }
181
+
182
+ /* --- Source code sections -------------------- */
183
+
184
+ a.source-toggle { font-size: 90%; }
185
+ div.method-source-code {
186
+ background: #262626;
187
+ color: #ffdead;
188
+ margin: 1em;
189
+ padding: 0.5em;
190
+ border: 1px dashed #999;
191
+ overflow: hidden;
192
+ }
193
+
194
+ div.method-source-code pre { color: #ffdead; overflow: hidden; }
195
+
196
+ /* --- Ruby keyword styles --------------------- */
197
+
198
+ .standalone-code { background: #221111; color: #ffdead; overflow: hidden; }
199
+
200
+ .ruby-constant { color: #7fffd4; background: transparent; }
201
+ .ruby-keyword { color: #00ffff; background: transparent; }
202
+ .ruby-ivar { color: #eedd82; background: transparent; }
203
+ .ruby-operator { color: #00ffee; background: transparent; }
204
+ .ruby-identifier { color: #ffdead; background: transparent; }
205
+ .ruby-node { color: #ffa07a; background: transparent; }
206
+ .ruby-comment { color: #b22222; font-weight: bold; background: transparent; }
207
+ .ruby-regexp { color: #ffa07a; background: transparent; }
208
+ .ruby-value { color: #7fffd4; background: transparent; }
@@ -1,11 +1,19 @@
1
1
  require 'date'
2
2
 
3
3
  class Date
4
+ # Return the equivalent date in a different year and optionally month.
5
+ # If the result of just changing the year and or month results in an invalid date
6
+ # e.g. September 31 in any year, or February 29 in a non-leap year, then return a valid
7
+ # date in the next month, see Date.civil_with_missing_day_correction
4
8
  def in_year_with_correction(yr,mth=month)
5
9
  Date.civil_with_missing_day_correction(yr, mth, day)
6
10
  end
7
11
  alias_method :in_year_and_month_with_correction, :in_year_with_correction
8
12
 
13
+ # Return a date with a given year, month and day. If the date would be invalid because that day does
14
+ # not exist in that month in that year, then return an equivalent date, 'reflected' around the end of the month.
15
+ # For example, Date.civil_with_missing_day_correction(2001, 2, 29) would return Date.civil(2001, 3, 1), and
16
+ # Date.civil_with_missing_day_correction(2011, 2, 31) would return Date.civil(2011, 3, 2)
9
17
  def self.civil_with_missing_day_correction(year, month, day)
10
18
  days_in_month = [
11
19
  # J F M A M J J A S O N D
@@ -19,37 +27,65 @@ class Date
19
27
  civil(year, month, day)
20
28
  end
21
29
 
22
- def years_months_days_since(date, debug = false)
23
- if date < self
24
- puts "#{self}.years_months_days_since(#{date})" if debug
25
- anniversary_this_year = date.in_year_with_correction(year)
30
+ # return a 3 element array comprising the number of years, months and days which have occurred between the argument
31
+ # initial_date and the receiver
32
+ #
33
+ # :call-seq:
34
+ # years_months_days_since(initial_date)
35
+ #
36
+ # The return values are
37
+ # 0. years - the number of anniversary dates which have occurred
38
+ # 1. months - the number of 'monthiversary' dates which have occurred since the last anniversary date
39
+ # 2. days - the number of days since the last monthiversary
40
+ #
41
+ # If the receiver is before the argument then years, months and days will be 0 or negative values.
42
+ def years_months_days_since(initial_date, debug = false)
43
+ if initial_date < self
44
+ puts "#{self}.years_months_days_since(#{initial_date})" if debug
45
+ anniversary_this_year = initial_date.in_year_with_correction(year)
26
46
  puts "anniversary_this_year is #{anniversary_this_year}" if debug
27
47
  years = if anniversary_this_year <= self
28
- year - date.year
48
+ year - initial_date.year
29
49
  else
30
- year - date.year - 1
50
+ year - initial_date.year - 1
31
51
  end
32
- last_monthiversary = monthiversary_this_month = date.in_year_and_month_with_correction(year, month)
52
+ last_monthiversary = monthiversary_this_month = initial_date.in_year_and_month_with_correction(year, month)
33
53
  puts "monthiversary_this_month is #{monthiversary_this_month}" if debug
34
54
  if (monthiversary_this_month > self)
35
55
  last_month = Date.civil(year, month, 1) << 1
36
- last_monthiversary = date.in_year_and_month_with_correction(last_month.year, last_month.month)
56
+ last_monthiversary = initial_date.in_year_and_month_with_correction(last_month.year, last_month.month)
37
57
  end
38
58
  puts "last_monthiversary is #{last_monthiversary}" if debug
39
59
 
40
- if last_monthiversary > date
60
+ if last_monthiversary > initial_date
41
61
  months = (last_monthiversary.month - anniversary_this_year.month)
42
62
  months += 12 if months < 0
43
63
  else
44
64
  months = 0
45
65
  end
46
66
  days = (self - last_monthiversary).to_i
47
- elsif date > self
48
- date.years_months_days_since(self, debug).map {|v| -v}
67
+ elsif initial_date > self
68
+ initial_date.years_months_days_since(self, debug).map {|v| -v}
49
69
  else
50
70
  years, months, days = 0, 0, 0
51
71
  end
52
72
 
53
73
  [years, months, days]
54
74
  end
75
+
76
+ # return a 3 element array comprising the number of years, months and days which will occur between the argument
77
+ # end_date and the receiver
78
+ #
79
+ # :call-seq:
80
+ # years_months_days_until(end_date)
81
+ #
82
+ # The return values are
83
+ # 0. years - the number of anniversary dates which will occur
84
+ # 1. months - the number of 'monthiversary' dates which will occur after the last anniversary date
85
+ # 2. days - the number of days after the last monthiversary
86
+ #
87
+ # If the receiver is after the argument then years, months and days will be 0 or negative values.
88
+ def years_months_days_until(end_date, debug = false)
89
+ end_date.years_months_days_since(self)
90
+ end
55
91
  end
@@ -1,3 +1,3 @@
1
1
  module Anniversary
2
- VERSION = "0.0.2"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -2,6 +2,24 @@
2
2
  require 'spec_helper'
3
3
  require 'anniversary.rb'
4
4
  describe "::Date" do
5
+
6
+ context "Date.civil_with_missing_day_correction" do
7
+ it "should handle a leap day jump" do
8
+ Date.civil_with_missing_day_correction(2011, 2, 29).should == Date.civil(2011, 3, 1)
9
+ end
10
+
11
+ it "should handle a normal short month jump" do
12
+ Date.civil_with_missing_day_correction(2011, 9, 31).should == Date.civil(2011, 10, 1)
13
+ end
14
+
15
+ it "should handle a multi-day jump in a leap year" do
16
+ Date.civil_with_missing_day_correction(2012, 2, 31).should == Date.civil(2012, 3, 2)
17
+ end
18
+
19
+ it "should handle a multi-day jump in a non-leap year" do
20
+ Date.civil_with_missing_day_correction(2011, 2, 31).should == Date.civil(2011, 3, 3)
21
+ end
22
+ end
5
23
 
6
24
  context "years_months_days_since" do
7
25
  def self.build_example(anniversary, subject, expected)
@@ -67,6 +85,6 @@ describe "::Date" do
67
85
 
68
86
  test_range( ::Date.civil(2000,6,1), ::Date.civil(2010,8,31))
69
87
  test_range( ::Date.civil(2000, 6, 15), ::Date.civil(2010,8,31))
70
-
88
+
71
89
  end
72
90
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anniversary
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease:
4
+ hash: 23
5
+ prerelease: false
6
6
  segments:
7
+ - 1
7
8
  - 0
8
9
  - 0
9
- - 2
10
- version: 0.0.2
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rick Denatale
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-13 00:00:00 -05:00
18
+ date: 2011-01-16 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -44,9 +44,25 @@ extra_rdoc_files: []
44
44
 
45
45
  files:
46
46
  - .gitignore
47
+ - .rvmrc
47
48
  - Gemfile
48
49
  - Rakefile
49
50
  - anniversary.gemspec
51
+ - doc/classes/Anniversary.html
52
+ - doc/classes/Date.html
53
+ - doc/classes/Date.src/M000001.html
54
+ - doc/classes/Date.src/M000003.html
55
+ - doc/classes/Date.src/M000004.html
56
+ - doc/classes/Date.src/M000005.html
57
+ - doc/created.rid
58
+ - doc/files/lib/anniversary/date_additions_rb.html
59
+ - doc/files/lib/anniversary/version_rb.html
60
+ - doc/files/lib/anniversary_rb.html
61
+ - doc/fr_class_index.html
62
+ - doc/fr_file_index.html
63
+ - doc/fr_method_index.html
64
+ - doc/index.html
65
+ - doc/rdoc-style.css
50
66
  - lib/anniversary.rb
51
67
  - lib/anniversary/date_additions.rb
52
68
  - lib/anniversary/version.rb
@@ -82,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
98
  requirements: []
83
99
 
84
100
  rubyforge_project: anniversary
85
- rubygems_version: 1.4.1
101
+ rubygems_version: 1.3.7
86
102
  signing_key:
87
103
  specification_version: 3
88
104
  summary: Add method to Ruby's Date to get [years, months, days] between two dates