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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12836b490a92bc840e8813971b18961e8937db6e
4
- data.tar.gz: cfb2ada216ea9649659e720425ecab1f3639a7ed
3
+ metadata.gz: 6c7d5467534e26cb3bb22d205c08b4b064651f71
4
+ data.tar.gz: 89bf8ac258976fbe3d95c8f3fd66e9908d5a72b8
5
5
  SHA512:
6
- metadata.gz: f1edf0d7587372b3475b5f80e716d6f355fe227653a3b972e70af069524effced0c4bf153ab1e11e67060fdab30fb54b9bac802e0bbdf3091818310ad6cf3423
7
- data.tar.gz: 428785f29fb442dee1cba0c1a5cee48348f654f12213a2e15fb4b944260d1f4a85bdd72143d36fb1ae7fb3af8ce96964fc77afeec7b47d35bdf0fbf24536fc27
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
- add_to_months offset % skip
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 >= date.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
- subtract_from_months offset % skip
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 <= date.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
@@ -1,3 +1,3 @@
1
1
  module Hiccup
2
- VERSION = "0.5.12"
2
+ VERSION = "0.5.13"
3
3
  end
@@ -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 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))
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 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))
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiccup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.12
4
+ version: 0.5.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail