anniversary 1.0.1 → 1.0.2
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/lib/anniversary/date_additions.rb +8 -5
- data/lib/anniversary/version.rb +1 -1
- data/spec/lib/date_additions_spec.rb +33 -18
- metadata +4 -4
@@ -49,13 +49,16 @@ class Date
|
|
49
49
|
else
|
50
50
|
year - initial_date.year - 1
|
51
51
|
end
|
52
|
-
last_monthiversary =
|
53
|
-
puts "
|
54
|
-
if (
|
52
|
+
last_monthiversary = initial_date.in_year_and_month_with_correction(year, month)
|
53
|
+
puts "last_monthiversary is #{last_monthiversary}" if debug
|
54
|
+
if (last_monthiversary > self)
|
55
55
|
last_month = Date.civil(year, month, 1) << 1
|
56
|
-
last_monthiversary
|
56
|
+
while (last_monthiversary > self)
|
57
|
+
last_monthiversary = initial_date.in_year_and_month_with_correction(last_month.year, last_month.month)
|
58
|
+
last_month = last_month << 1
|
59
|
+
end
|
57
60
|
end
|
58
|
-
puts "last_monthiversary is #{last_monthiversary}" if debug
|
61
|
+
puts "last_monthiversary after correction is #{last_monthiversary}" if debug
|
59
62
|
|
60
63
|
if last_monthiversary > initial_date
|
61
64
|
months = (last_monthiversary.month - anniversary_this_year.month)
|
data/lib/anniversary/version.rb
CHANGED
@@ -2,20 +2,20 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
require 'anniversary.rb'
|
4
4
|
describe "::Date" do
|
5
|
-
|
5
|
+
|
6
6
|
context "Date.civil_with_missing_day_correction" do
|
7
7
|
it "should handle a leap day jump" do
|
8
8
|
Date.civil_with_missing_day_correction(2011, 2, 29).should == Date.civil(2011, 3, 1)
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
it "should handle a normal short month jump" do
|
12
12
|
Date.civil_with_missing_day_correction(2011, 9, 31).should == Date.civil(2011, 10, 1)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
it "should handle a multi-day jump in a leap year" do
|
16
16
|
Date.civil_with_missing_day_correction(2012, 2, 31).should == Date.civil(2012, 3, 2)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
it "should handle a multi-day jump in a non-leap year" do
|
20
20
|
Date.civil_with_missing_day_correction(2011, 2, 31).should == Date.civil(2011, 3, 3)
|
21
21
|
end
|
@@ -28,7 +28,7 @@ describe "::Date" do
|
|
28
28
|
subject.years_months_days_since(anniversary).should == [eyd, emd, edd]
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def self.test_range(anniversary, last_date_to_test)
|
33
33
|
raise "Dates are incompatible" if last_date_to_test < anniversary
|
34
34
|
expected_year_diff = 0
|
@@ -38,7 +38,7 @@ describe "::Date" do
|
|
38
38
|
next_anniversary = ::Date.civil_with_missing_day_correction(test_date.year + 1, test_date.month, test_date.day)
|
39
39
|
next_month = ::Date.civil(test_date.year, test_date.month, 1) >> 1
|
40
40
|
next_monthiversary = ::Date.civil_with_missing_day_correction(next_month.year, next_month.month, test_date.day)
|
41
|
-
|
41
|
+
|
42
42
|
while (test_date <= last_date_to_test) do
|
43
43
|
build_example(anniversary, test_date, [expected_year_diff, expected_month_diff, expected_day_diff])
|
44
44
|
expected_day_diff += 1
|
@@ -57,34 +57,49 @@ describe "::Date" do
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
it "should give zeroes for the same date" do
|
62
62
|
anniversary = ::Date.civil(2001, 6, 1)
|
63
63
|
target = ::Date.civil(2001, 6, 1)
|
64
|
-
target.years_months_days_since(anniversary).should == [0, 0, 0]
|
64
|
+
target.years_months_days_since(anniversary).should == [0, 0, 0]
|
65
65
|
end
|
66
|
-
|
67
|
-
it "should handle a case where the date is in the next calendar month, but before the
|
66
|
+
|
67
|
+
it "should handle a case where the date is in the next calendar month, but before the monthiversary" do
|
68
68
|
anniversary = ::Date.civil(2001, 6, 15)
|
69
69
|
target = ::Date.civil(2001, 7, 1)
|
70
|
-
target.years_months_days_since(anniversary).should == [0, 0, 16]
|
70
|
+
target.years_months_days_since(anniversary).should == [0, 0, 16]
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
it "should handle a case where the date is one month after an anniversary on the first of the month" do
|
74
74
|
anniversary = ::Date.civil(2001, 6, 1)
|
75
75
|
target = ::Date.civil(2001, 7, 1)
|
76
|
-
target.years_months_days_since(anniversary).should == [0, 1, 0]
|
76
|
+
target.years_months_days_since(anniversary).should == [0, 1, 0]
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
it "should handle a case where the date is new years day after the anniversary" do
|
80
80
|
anniversary = ::Date.civil(2001, 6, 1)
|
81
81
|
target = ::Date.civil(2002, 1, 1)
|
82
|
-
target.years_months_days_since(anniversary).should == [0, 7, 0]
|
82
|
+
target.years_months_days_since(anniversary).should == [0, 7, 0]
|
83
83
|
end
|
84
|
-
|
85
|
-
|
84
|
+
|
85
|
+
it "should handle the case of March 1, January 31 in the same non leap year" do
|
86
|
+
Date.civil(2010,3,1).years_months_days_since(Date.civil(2010,1,31)).should == [0, 0, 29]
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should handle the case of March 1, January 31 in the same leap year" do
|
90
|
+
Date.civil(2008,3,1).years_months_days_since(Date.civil(2008,1,31)).should == [0, 0, 30]
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should handle the first case brought up by pit capitan's comment on the blog" do
|
94
|
+
Date.civil(2010,7,4).years_months_days_since(Date.civil(1970,1,31)).should == [40, 6, 3]
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should handle the second case brought up by pit capitan's comment on the blog" do
|
98
|
+
Date.civil(2010,7,4).years_months_days_since(Date.civil(1970,2,1)).should == [40, 5, 3]
|
99
|
+
end
|
100
|
+
|
86
101
|
test_range( ::Date.civil(2000,6,1), ::Date.civil(2010,8,31))
|
87
102
|
test_range( ::Date.civil(2000, 6, 15), ::Date.civil(2010,8,31))
|
88
|
-
|
103
|
+
|
89
104
|
end
|
90
105
|
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:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
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-
|
18
|
+
date: 2011-01-22 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|