hiccup 0.5.15 → 0.5.16
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 +10 -4
- data/lib/hiccup/version.rb +1 -1
- data/test/monthly_enumerator_test.rb +59 -0
- 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: 5360432a77538aebc70858cfabaa86053f0de7d2
|
4
|
+
data.tar.gz: f6b1a1605bcb80ab578dda9b44c2dc6d50199c23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d1ed6207b1477718f353df54ff3b5bd430d0f4ff223fcf312a7419165decee220cf0b8981ad54c2d768b4528d2a8f101e4104206f2e499fa557e7a05e658829
|
7
|
+
data.tar.gz: 5b9dd9c74e8b5baf294e5a108a82933bdf179740cb1083d56d7339fc33576ed5defc074af775eb94a999a1ba1d284cff944c0470f949d579b7c555289367d59e
|
@@ -102,15 +102,21 @@ module Hiccup
|
|
102
102
|
|
103
103
|
|
104
104
|
def occurrences_in_month(year, month)
|
105
|
-
wday_of_first_of_month = Date.new(year, month, 1).wday
|
106
105
|
monthly_pattern.map do |occurrence|
|
107
106
|
if occurrence.is_a?(Array)
|
108
107
|
ordinal, weekday = occurrence
|
109
108
|
wday = Date::DAYNAMES.index(weekday)
|
110
109
|
day = wday
|
111
|
-
|
112
|
-
|
113
|
-
|
110
|
+
if ordinal < 0
|
111
|
+
wday_of_last_of_month = Date.new(year, month, -1).wday
|
112
|
+
day = day + 7 if wday <= wday_of_last_of_month
|
113
|
+
day = day - wday_of_last_of_month + (ordinal * 7) - 1
|
114
|
+
else
|
115
|
+
wday_of_first_of_month = Date.new(year, month, 1).wday
|
116
|
+
day = day + 7 if (wday < wday_of_first_of_month)
|
117
|
+
day = day - wday_of_first_of_month
|
118
|
+
day = day + (ordinal * 7) - 6
|
119
|
+
end
|
114
120
|
day
|
115
121
|
else
|
116
122
|
occurrence
|
data/lib/hiccup/version.rb
CHANGED
@@ -69,6 +69,65 @@ class MonthlyEnumeratorTest < ActiveSupport::TestCase
|
|
69
69
|
end
|
70
70
|
|
71
71
|
|
72
|
+
context "last of the month" do
|
73
|
+
should "return the last day of the month" do
|
74
|
+
date = Date.new(2014, 12, 31)
|
75
|
+
@schedule = Schedule.new(
|
76
|
+
kind: :monthly,
|
77
|
+
monthly_pattern: [-1],
|
78
|
+
start_date: date
|
79
|
+
)
|
80
|
+
enumerator = @schedule.enumerator.new(@schedule, date)
|
81
|
+
assert_equal Date.new(2015, 1, 31), enumerator.next
|
82
|
+
assert_equal Date.new(2015, 2, 28), enumerator.next
|
83
|
+
assert_equal Date.new(2015, 3, 31), enumerator.next
|
84
|
+
end
|
85
|
+
|
86
|
+
should "return the last sunday of the month" do
|
87
|
+
date = Date.new(2014, 12, 31)
|
88
|
+
@schedule = Schedule.new(
|
89
|
+
kind: :monthly,
|
90
|
+
monthly_pattern: [[-1, "Sunday"]],
|
91
|
+
start_date: date
|
92
|
+
)
|
93
|
+
enumerator = @schedule.enumerator.new(@schedule, date)
|
94
|
+
assert_equal Date.new(2015, 1, 25), enumerator.next
|
95
|
+
end
|
96
|
+
|
97
|
+
should "return the last monday of the month" do
|
98
|
+
date = Date.new(2014, 12, 31)
|
99
|
+
@schedule = Schedule.new(
|
100
|
+
kind: :monthly,
|
101
|
+
monthly_pattern: [[-1, "Monday"]],
|
102
|
+
start_date: date
|
103
|
+
)
|
104
|
+
enumerator = @schedule.enumerator.new(@schedule, Date.new(2015, 2, 28))
|
105
|
+
assert_equal Date.new(2015, 3, 30), enumerator.next
|
106
|
+
end
|
107
|
+
|
108
|
+
should "return the last tuesday of the month" do
|
109
|
+
date = Date.new(2014, 12, 31)
|
110
|
+
@schedule = Schedule.new(
|
111
|
+
kind: :monthly,
|
112
|
+
monthly_pattern: [[-1, "Tuesday"]],
|
113
|
+
start_date: date
|
114
|
+
)
|
115
|
+
enumerator = @schedule.enumerator.new(@schedule, Date.new(2015, 1, 31))
|
116
|
+
assert_equal Date.new(2015, 2, 24), enumerator.next
|
117
|
+
end
|
118
|
+
|
119
|
+
should "return the second to last tuesday of the month" do
|
120
|
+
date = Date.new(2014, 12, 31)
|
121
|
+
@schedule = Schedule.new(
|
122
|
+
kind: :monthly,
|
123
|
+
monthly_pattern: [[-2, "Tuesday"]],
|
124
|
+
start_date: date
|
125
|
+
)
|
126
|
+
enumerator = @schedule.enumerator.new(@schedule, Date.new(2015, 2, 28))
|
127
|
+
assert_equal Date.new(2015, 2, 17), enumerator.prev
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
72
131
|
context "with an empty schedule" do
|
73
132
|
setup do
|
74
133
|
@schedule = Schedule.new(
|
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.16
|
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-
|
11
|
+
date: 2015-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|