hiccup 0.5.11 → 0.5.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hiccup/enumerable/monthly_enumerator.rb +27 -4
- data/lib/hiccup/version.rb +1 -1
- data/test/monthly_enumerator_test.rb +26 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12836b490a92bc840e8813971b18961e8937db6e
|
4
|
+
data.tar.gz: cfb2ada216ea9649659e720425ecab1f3639a7ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1edf0d7587372b3475b5f80e716d6f355fe227653a3b972e70af069524effced0c4bf153ab1e11e67060fdab30fb54b9bac802e0bbdf3091818310ad6cf3423
|
7
|
+
data.tar.gz: 428785f29fb442dee1cba0c1a5cee48348f654f12213a2e15fb4b944260d1f4a85bdd72143d36fb1ae7fb3af8ce96964fc77afeec7b47d35bdf0fbf24536fc27
|
@@ -52,6 +52,11 @@ module Hiccup
|
|
52
52
|
|
53
53
|
def first_occurrence_on_or_after(date)
|
54
54
|
@year, @month = date.year, date.month
|
55
|
+
if skip > 1
|
56
|
+
offset = months_since_schedule_start(@year, @month)
|
57
|
+
add_to_months offset % skip
|
58
|
+
end
|
59
|
+
|
55
60
|
get_context
|
56
61
|
|
57
62
|
@position = cycle.index { |day| day >= date.day }
|
@@ -66,6 +71,11 @@ module Hiccup
|
|
66
71
|
|
67
72
|
def first_occurrence_on_or_before(date)
|
68
73
|
@year, @month = date.year, date.month
|
74
|
+
if skip > 1
|
75
|
+
offset = months_since_schedule_start(@year, @month)
|
76
|
+
subtract_from_months offset % skip
|
77
|
+
end
|
78
|
+
|
69
79
|
get_context
|
70
80
|
|
71
81
|
@position = cycle.rindex { |day| day <= date.day }
|
@@ -101,18 +111,26 @@ module Hiccup
|
|
101
111
|
|
102
112
|
def next_month
|
103
113
|
@position = 0
|
104
|
-
|
105
|
-
@year, @month = year + 1, month - 12 if month > 12
|
114
|
+
add_to_months skip
|
106
115
|
get_context
|
107
116
|
end
|
108
117
|
|
118
|
+
def add_to_months(offset)
|
119
|
+
@month += offset
|
120
|
+
@year, @month = @year + 1, @month - 12 while @month > 12
|
121
|
+
end
|
122
|
+
|
109
123
|
def prev_month
|
110
124
|
@position = @cycle.length - 1
|
111
|
-
|
112
|
-
@year, @month = year - 1, month + 12 if month < 1
|
125
|
+
subtract_from_months skip
|
113
126
|
get_context
|
114
127
|
end
|
115
128
|
|
129
|
+
def subtract_from_months(offset)
|
130
|
+
@month -= offset
|
131
|
+
@year, @month = @year - 1, @month + 12 while @month < 1
|
132
|
+
end
|
133
|
+
|
116
134
|
def get_context
|
117
135
|
@last_day_of_month = [4, 6, 9, 11].member?(month) ? 30 : 31
|
118
136
|
@last_day_of_month = leap_year?(year) ? 29 : 28 if month == 2
|
@@ -121,6 +139,11 @@ module Hiccup
|
|
121
139
|
|
122
140
|
|
123
141
|
|
142
|
+
def months_since_schedule_start(year, month)
|
143
|
+
(year - start_date.year) * 12 + (month - start_date.month)
|
144
|
+
end
|
145
|
+
|
146
|
+
|
124
147
|
end
|
125
148
|
end
|
126
149
|
end
|
data/lib/hiccup/version.rb
CHANGED
@@ -22,7 +22,6 @@ class MonthlyEnumeratorTest < ActiveSupport::TestCase
|
|
22
22
|
end
|
23
23
|
|
24
24
|
context "when enumerating backward" do
|
25
|
-
|
26
25
|
should "return the most-recent date prior to the start_date, NOT the earliest date in the month" do
|
27
26
|
# Start with a date in the middle of the month
|
28
27
|
# More than one date prior to the seed date, yet
|
@@ -31,8 +30,33 @@ class MonthlyEnumeratorTest < ActiveSupport::TestCase
|
|
31
30
|
enumerator = @schedule.enumerator.new(@schedule, date)
|
32
31
|
assert_equal Date.new(2013, 10, 13), enumerator.prev
|
33
32
|
end
|
34
|
-
|
35
33
|
end
|
36
34
|
end
|
37
35
|
|
36
|
+
|
37
|
+
context "with a schedule that skips" do
|
38
|
+
setup do
|
39
|
+
@schedule = Schedule.new(
|
40
|
+
kind: :monthly,
|
41
|
+
skip: 2,
|
42
|
+
monthly_pattern: [[1, "Thursday"]],
|
43
|
+
start_date: Date.new(2015, 1, 1))
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when enumerating from the start date" do
|
47
|
+
should "skip months from the schedule's start date" do
|
48
|
+
assert_equal [Date.new(2015, 1, 1), Date.new(2015, 3, 5), Date.new(2015, 5, 7)],
|
49
|
+
@schedule.occurrences_between(Date.new(2015, 1, 1), Date.new(2015, 5, 31))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when enumerating from an offset" do
|
54
|
+
should "skip months from the schedule's start date not from the offset" do
|
55
|
+
assert_equal [Date.new(2015, 3, 5), Date.new(2015, 5, 7)],
|
56
|
+
@schedule.occurrences_between(Date.new(2015, 2, 1), Date.new(2015, 6, 30))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
38
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiccup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Lail
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|