Skip to content

Commit

Permalink
Modernize BYSETPOS commit
Browse files Browse the repository at this point in the history
A few small updates to Nicolas Marlier's BYSETPOS support added in
PR ice-cube-ruby#349
  • Loading branch information
nehresma authored and davidstosik committed Feb 6, 2019
1 parent 04290ec commit 51ea4a1
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
4 changes: 1 addition & 3 deletions lib/ice_cube/validations/monthly_by_set_pos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module IceCube
module Validations::MonthlyBySetPos

def by_set_pos(*by_set_pos)
return by_set_pos([by_set_pos]) if by_set_pos.is_a?(Fixnum)
return by_set_pos([by_set_pos]) if by_set_pos.is_a?(Integer)

unless by_set_pos.nil? || by_set_pos.is_a?(Array)
raise ArgumentError, "Expecting Array or nil value for count, got #{by_set_pos.inspect}"
Expand Down Expand Up @@ -48,9 +48,7 @@ def validate(step_time, schedule)
s.add_recurrence_rule IceCube::Rule.from_hash(rule.to_hash.reject{|k, v| [:by_set_pos, :count, :until].include? k})
end

puts step_time
occurrences = new_schedule.occurrences_between(start_of_month, end_of_month)
p occurrences
index = occurrences.index(step_time)
if index == nil
1
Expand Down
2 changes: 1 addition & 1 deletion lib/ice_cube/validations/yearly_by_set_pos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module IceCube
module Validations::YearlyBySetPos

def by_set_pos(*by_set_pos)
return by_set_pos([by_set_pos]) if by_set_pos.is_a?(Fixnum)
return by_set_pos([by_set_pos]) if by_set_pos.is_a?(Integer)

unless by_set_pos.nil? || by_set_pos.is_a?(Array)
raise ArgumentError, "Expecting Array or nil value for count, got #{by_set_pos.inspect}"
Expand Down
2 changes: 1 addition & 1 deletion spec/examples/from_ical_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module IceCube

it 'should be able to parse by_set_pos start (BYSETPOS)' do
rule = IceCube::Rule.from_ical("FREQ=MONTHLY;BYDAY=MO,WE;BYSETPOS=-1,1")
rule.should == IceCube::Rule.monthly.day(:monday, :wednesday).by_set_pos([-1, 1])
expect(rule).to eq(IceCube::Rule.monthly.day(:monday, :wednesday).by_set_pos([-1, 1]))
end

it 'should return no occurrences after daily interval with count is over' do
Expand Down

0 comments on commit 51ea4a1

Please sign in to comment.