From e5b861613d47f7039ca3930bbd25cd0604169012 Mon Sep 17 00:00:00 2001 From: MitzaCeusan Date: Tue, 8 Nov 2011 19:10:01 +0200 Subject: [PATCH 1/3] allow monthly schedules --- lib/schedule_atts.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/schedule_atts.rb b/lib/schedule_atts.rb index aa47472..01bdf2f 100644 --- a/lib/schedule_atts.rb +++ b/lib/schedule_atts.rb @@ -34,6 +34,8 @@ def schedule_attributes=(options) 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' @@ -63,6 +65,8 @@ 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 From 7eed1a5f4093b15d14a745a4640ceb5b8df850e3 Mon Sep 17 00:00:00 2001 From: MitzaCeusan Date: Mon, 10 Feb 2014 18:53:16 +0200 Subject: [PATCH 2/3] use the same syntax for end_time that ice_cube requires --- lib/schedule_atts.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/schedule_atts.rb b/lib/schedule_atts.rb index 01bdf2f..2c0b1af 100644 --- a/lib/schedule_atts.rb +++ b/lib/schedule_atts.rb @@ -21,13 +21,13 @@ def schedule_attributes=(options) options[:interval] = options[:interval].to_i options[:start_date] &&= ScheduleAttributes.parse_in_timezone(options[:start_date]) options[:date] &&= ScheduleAttributes.parse_in_timezone(options[: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' 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' @@ -38,8 +38,6 @@ def schedule_attributes=(options) IceCube::Rule.monthly options[:interval] end - rule.until(options[:until_date]) if options[:ends] == 'eventually' - @schedule.add_recurrence_rule(rule) end @@ -70,7 +68,7 @@ def schedule_attributes 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' From 24bf9e8c64f19a0f2a10df028c8451aec9ccac34 Mon Sep 17 00:00:00 2001 From: Ian Smith Date: Mon, 24 Feb 2014 15:10:25 -0700 Subject: [PATCH 3/3] make specs pass, make schedule_attributes return accurate info, make schedule_attributes= set end time --- Gemfile | 2 +- Gemfile.lock | 19 +------------------ lib/schedule_atts.rb | 16 +++++++++++----- lib/schedule_atts/version.rb | 2 +- schedule_atts.gemspec | 8 ++++---- spec/schedule_atts_spec.rb | 5 +++-- 6 files changed, 21 insertions(+), 31 deletions(-) diff --git a/Gemfile b/Gemfile index d1693d7..311becf 100644 --- a/Gemfile +++ b/Gemfile @@ -4,4 +4,4 @@ source "http://rubygems.org" gemspec gem 'autotest' -gem 'ruby-debug19' +# gem 'debugger' diff --git a/Gemfile.lock b/Gemfile.lock index 1261fd5..d129a9b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - schedule_atts (0.0.1) + schedule_atts (0.0.2) activesupport ice_cube (>= 0.6.4) @@ -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) @@ -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! diff --git a/lib/schedule_atts.rb b/lib/schedule_atts.rb index 2c0b1af..76e1fc1 100644 --- a/lib/schedule_atts.rb +++ b/lib/schedule_atts.rb @@ -19,9 +19,10 @@ 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[:end_time] &&= ScheduleAttributes.parse_in_timezone(options[:end_time]) if options[:ends] == 'eventually' + # 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]) @@ -38,6 +39,8 @@ def schedule_attributes=(options) IceCube::Rule.monthly options[:interval] end + rule.until(options[:end_time]) if options[:ends] == 'eventually' + @schedule.add_recurrence_rule(rule) end @@ -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 @@ -68,6 +73,7 @@ def schedule_attributes 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 @@ -75,7 +81,7 @@ def schedule_attributes 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 diff --git a/lib/schedule_atts/version.rb b/lib/schedule_atts/version.rb index a5916bd..05cca37 100644 --- a/lib/schedule_atts/version.rb +++ b/lib/schedule_atts/version.rb @@ -1,3 +1,3 @@ module ScheduleAtts - VERSION = "0.0.1" + VERSION = "0.0.2" end diff --git a/schedule_atts.gemspec b/schedule_atts.gemspec index 365682f..e11c867 100644 --- a/schedule_atts.gemspec +++ b/schedule_atts.gemspec @@ -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.} diff --git a/spec/schedule_atts_spec.rb b/spec/schedule_atts_spec.rb index 6f506ba..3d713cc 100644 --- a/spec/schedule_atts_spec.rb +++ b/spec/schedule_atts_spec.rb @@ -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) } @@ -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