Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow monthly scheduling #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ source "http://rubygems.org"
gemspec

gem 'autotest'
gem 'ruby-debug19'
# gem 'debugger'
19 changes: 1 addition & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
schedule_atts (0.0.1)
schedule_atts (0.0.2)
activesupport
ice_cube (>= 0.6.4)

Expand All @@ -10,15 +10,11 @@ GEM
specs:
ZenTest (4.4.2)
activesupport (3.0.3)
archive-tar-minitar (0.5.2)
autotest (4.4.6)
ZenTest (>= 4.4.1)
columnize (0.3.2)
diff-lcs (1.1.2)
facets (2.9.0)
ice_cube (0.6.4)
linecache19 (0.5.11)
ruby_core_source (>= 0.1.4)
rspec (2.3.0)
rspec-core (~> 2.3.0)
rspec-expectations (~> 2.3.0)
Expand All @@ -27,25 +23,12 @@ GEM
rspec-expectations (2.3.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.3.0)
ruby-debug-base19 (0.11.24)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby_core_source (>= 0.1.4)
ruby-debug19 (0.11.6)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby-debug-base19 (>= 0.11.19)
ruby_core_source (0.1.4)
archive-tar-minitar (>= 0.5.2)

PLATFORMS
ruby

DEPENDENCIES
activesupport
autotest
facets
ice_cube (>= 0.6.4)
rspec (>= 2.3)
ruby-debug19
schedule_atts!
22 changes: 15 additions & 7 deletions lib/schedule_atts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,27 @@ def schedule
def schedule_attributes=(options)
options = options.dup
options[:interval] = options[:interval].to_i
options[:start_date] &&= ScheduleAttributes.parse_in_timezone(options[:start_date])
options[:start_date] &&= ScheduleAttributes.parse_in_timezone(options[:start_date]) # IS: in icecube master, start_date is deprecated in favor of start_time
options[:date] &&= ScheduleAttributes.parse_in_timezone(options[:date])
options[:until_date] &&= ScheduleAttributes.parse_in_timezone(options[:until_date])
# options[:until_date] &&= ScheduleAttributes.parse_in_timezone(options[:until_date])
options[:end_time] &&= ScheduleAttributes.parse_in_timezone(options[:end_time]) if options[:ends] == 'eventually' # IS: in icecube master, end_time is deprecated in favor of until_time

if options[:repeat].to_i == 0
@schedule = IceCube::Schedule.new(options[:date])
@schedule.add_recurrence_date(options[:date])
else
@schedule = IceCube::Schedule.new(options[:start_date])
@schedule = IceCube::Schedule.new(options[:start_date], options)

rule = case options[:interval_unit]
when 'day'
IceCube::Rule.daily options[:interval]
when 'week'
IceCube::Rule.weekly(options[:interval]).day( *IceCube::DAYS.keys.select{|day| options[day].to_i == 1 } )
when 'month'
IceCube::Rule.monthly options[:interval]
end

rule.until(options[:until_date]) if options[:ends] == 'eventually'
rule.until(options[:end_time]) if options[:ends] == 'eventually'

@schedule.add_recurrence_rule(rule)
end
Expand All @@ -47,9 +50,11 @@ def schedule_attributes=(options)
def schedule_attributes
atts = {}

if rule = schedule.rrules.first
s = schedule_yaml ? IceCube::Schedule.from_yaml(schedule_yaml) : schedule

if rule = s.rrules.last
atts[:repeat] = 1
atts[:start_date] = schedule.start_date.to_date
atts[:start_date] = s.start_date.to_date
atts[:date] = Date.today # for populating the other part of the form

rule_hash = rule.to_hash
Expand All @@ -63,17 +68,20 @@ def schedule_attributes
rule_hash[:validations][:day].each do |day_idx|
atts[ DAY_NAMES[day_idx] ] = 1
end
when IceCube::MonthlyRule
atts[:interval_unit] = 'month'
end

if rule.until_date
atts[:until_date] = rule.until_date.to_date
atts[:end_time] = rule.until_date.to_date
atts[:ends] = 'eventually'
else
atts[:ends] = 'never'
end
else
atts[:repeat] = 0
atts[:date] = schedule.start_date.to_date
atts[:date] = s.start_date.to_date
atts[:start_date] = Date.today # for populating the other part of the form
end

Expand Down
2 changes: 1 addition & 1 deletion lib/schedule_atts/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ScheduleAtts
VERSION = "0.0.1"
VERSION = "0.0.2"
end
8 changes: 4 additions & 4 deletions schedule_atts.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ require "schedule_atts/version"

Gem::Specification.new do |s|
s.name = "schedule_atts"
s.version = ScheduleAtts::VERSION
s.version = "0.0.2"
s.platform = Gem::Platform::RUBY
s.authors = ["Mike Nicholaides"]
s.email = ["mike@ablegray.com"]
s.homepage = "http://ablegray.com"
s.authors = ["Mike Nicholaides, but then people at Kapost"]
s.email = ["mike@ablegray.com / dev@kapost.com"]
s.homepage = "http://ablegray.com / kapost.com"
s.summary = %q{Provides form attributes setting a recurring schedule.}
s.description = %q{Provides form attributes setting a recurring schedule.}

Expand Down
5 changes: 3 additions & 2 deletions spec/schedule_atts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
end

context "given :interval_unit=>day & :ends=>eventually & :until_date" do
let(:schedule_attributes){ { :repeat => '1', :start_date => '1-1-1985', :interval_unit => 'day', :interval => '3', :until_date => '29-12-1985', :ends => 'eventually' } }
let(:schedule_attributes){ { :repeat => '1', :start_date => '1-1-1985', :interval_unit => 'day', :interval => '3', :end_time => '29-12-1985', :ends => 'eventually' } }
its(:start_date){ should == Date.new(1985, 1, 1).to_time }
its(:rrules){ should == [ IceCube::Rule.daily(3).until(Date.new(1985, 12, 29).to_time) ] }
it{ subject.first(3).should == [Date.civil(1985, 1, 1), Date.civil(1985, 1, 4), Date.civil(1985, 1, 7)].map(&:to_time) }
Expand Down Expand Up @@ -99,9 +99,10 @@
before do
schedule.add_recurrence_rule(IceCube::Rule.daily(4).until((Date.today+10).to_time))
end
it{ should == OpenStruct.new(:repeat => 1, :start_date => Date.tomorrow, :interval_unit => 'day', :interval => 4, :ends => 'eventually', :until_date => Date.today+10, :date => Date.today) }
it{ should == OpenStruct.new(:repeat => 1, :start_date => Date.tomorrow, :interval_unit => 'day', :interval => 4, :ends => 'eventually', :until_date => Date.today+10, :date => Date.today, :end_time => Date.today+10) }
its(:start_date){ should be_a(Date) }
its(:until_date){ should be_a(Date) }
its(:ends){ should eql("eventually") }
end

context "when it repeats weekly" do
Expand Down