hiccup 0.5.12 → 0.5.13
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.
- checksums.yaml +4 -4
- data/lib/hiccup/enumerable/monthly_enumerator.rb +19 -6
- data/lib/hiccup/version.rb +1 -1
- data/test/monthly_enumerator_test.rb +18 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c7d5467534e26cb3bb22d205c08b4b064651f71
|
4
|
+
data.tar.gz: 89bf8ac258976fbe3d95c8f3fd66e9908d5a72b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37af0836777d27ec8bc5b0b4fa83a6bc77baf71108a50d80401cf1a314be919c817aac5c1aa1651d7bb31f245f2c7c5989361c910d01e1c9ab4640332faaefa0
|
7
|
+
data.tar.gz: 559990a51e3b9bc7b62da61f5036e53a937110e09f60ec9db4e6879f8811d4a84a4e40512275beb171773d8b214261769757a1c8d69a3e5b2303215c3e8abd1c
|
@@ -51,15 +51,19 @@ module Hiccup
|
|
51
51
|
|
52
52
|
|
53
53
|
def first_occurrence_on_or_after(date)
|
54
|
-
@year, @month = date.year, date.month
|
54
|
+
@year, @month, seed_day = date.year, date.month, date.day
|
55
55
|
if skip > 1
|
56
56
|
offset = months_since_schedule_start(@year, @month)
|
57
|
-
|
57
|
+
remainder = offset % skip
|
58
|
+
if remainder > 0
|
59
|
+
add_to_months remainder
|
60
|
+
seed_day = first_day_of_month
|
61
|
+
end
|
58
62
|
end
|
59
63
|
|
60
64
|
get_context
|
61
65
|
|
62
|
-
@position = cycle.index { |day| day >=
|
66
|
+
@position = cycle.index { |day| day >= seed_day }
|
63
67
|
next_month unless @position
|
64
68
|
|
65
69
|
day = cycle[@position]
|
@@ -70,15 +74,20 @@ module Hiccup
|
|
70
74
|
end
|
71
75
|
|
72
76
|
def first_occurrence_on_or_before(date)
|
73
|
-
@year, @month = date.year, date.month
|
77
|
+
@year, @month, seed_day = date.year, date.month, date.day
|
74
78
|
if skip > 1
|
75
79
|
offset = months_since_schedule_start(@year, @month)
|
76
|
-
|
80
|
+
remainder = offset % skip
|
81
|
+
if remainder > 0
|
82
|
+
subtract_from_months remainder
|
83
|
+
get_context # figure out last_day_of_month
|
84
|
+
seed_day = last_day_of_month
|
85
|
+
end
|
77
86
|
end
|
78
87
|
|
79
88
|
get_context
|
80
89
|
|
81
|
-
@position = cycle.rindex { |day| day <=
|
90
|
+
@position = cycle.rindex { |day| day <= seed_day }
|
82
91
|
prev_month unless @position
|
83
92
|
|
84
93
|
day = cycle[@position]
|
@@ -143,6 +152,10 @@ module Hiccup
|
|
143
152
|
(year - start_date.year) * 12 + (month - start_date.month)
|
144
153
|
end
|
145
154
|
|
155
|
+
def first_day_of_month
|
156
|
+
1
|
157
|
+
end
|
158
|
+
|
146
159
|
|
147
160
|
end
|
148
161
|
end
|
data/lib/hiccup/version.rb
CHANGED
@@ -43,17 +43,27 @@ class MonthlyEnumeratorTest < ActiveSupport::TestCase
|
|
43
43
|
start_date: Date.new(2015, 1, 1))
|
44
44
|
end
|
45
45
|
|
46
|
-
context "when enumerating from
|
47
|
-
should "skip months from the schedule's start date" do
|
48
|
-
|
49
|
-
|
46
|
+
context "when enumerating from a date in a skipped month" do
|
47
|
+
should "skip months from the schedule's start date not from the offset" do
|
48
|
+
date = Date.new(2015, 2, 1)
|
49
|
+
enumerator = @schedule.enumerator.new(@schedule, date)
|
50
|
+
assert_equal Date.new(2015, 3, 5), enumerator.next
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
|
-
context "when enumerating from
|
54
|
-
should "
|
55
|
-
|
56
|
-
|
54
|
+
context "when enumerating forward from a date toward the end of a skipped month" do
|
55
|
+
should "find the first date from the start of an unskipped month" do
|
56
|
+
date = Date.new(2015, 4, 30)
|
57
|
+
enumerator = @schedule.enumerator.new(@schedule, date)
|
58
|
+
assert_equal Date.new(2015, 5, 7), enumerator.next
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when enumerating backward from a date toward the beginning of a skipped month" do
|
63
|
+
should "find the first date from the end of an unskipped month" do
|
64
|
+
date = Date.new(2015, 6, 1)
|
65
|
+
enumerator = @schedule.enumerator.new(@schedule, date)
|
66
|
+
assert_equal Date.new(2015, 5, 7), enumerator.prev
|
57
67
|
end
|
58
68
|
end
|
59
69
|
end
|