Giter Site home page Giter Site logo

ice_cube's People

Contributors

ajsharp avatar albertosaurus avatar avit avatar defeated avatar dgilperez avatar dnrce avatar donaldpiret avatar donapieppo avatar epinault avatar flink avatar forrest avatar fwininger avatar hughkelsey avatar jakebrady5 avatar jopotts avatar kogre avatar lubmes avatar mitzaceusan avatar mrloop avatar olleolleolle avatar pacso avatar patrickjaberg avatar philcoggins avatar promisedlandt avatar robinroestenburg avatar ryansch avatar seejohnrun avatar tpickett66 avatar wvengen avatar yurijmi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ice_cube's Issues

Creating a time

Can you please give another example of using hour_of_day and minute_of_hour?

How would you encode daily from 11:15am to 12:45pm?

I tried doing something simpler but I couldn't get it to work:

schedule = Schedule.new(Time.now)
schedule.add_recurrence_rule Rule.daily(1).hour_of_day(10)
schedule.occurs_at?(Time.now)  
=> false
Time.now 
=> Tue Jun 01 10:10:30 -0500 2010

Am I doing this wrong?

bug in occurs_at in combination with recurrence_dates

When adding dates using recurrence_dates, the occures_at returns a wrong value:

require 'ice_cube'

s = IceCube::Schedule.new(Time.new(2011,10,1, 18, 25))
s.add_recurrence_date(Time.new(2011,12,3,15,0,0))
s.add_recurrence_date(Time.new(2011,12,3,10,0,0)) 
s.add_recurrence_date(Time.new(2011,12,4,10,0,0))

p s.next_occurrences(12)

# Will return false, but it should return true
p s.occurs_at?(Time.new(2011,12,3,15,0,0))

This is because the method find_occurrences that is called in the occurrences method does only filter the rules, not the recurrence dates.

Integrate in a calendar

Hi guys,

I want to know if it's possible to integrate IceCube gem with FullCalendar, for viewing recurring events in a calendar.

If it does, anyone could tell me how?

Thanks...

View options

Is there an easy way to display the different day options for lets say a week view and add them to the hash without going through hardcoding the days?

My code right now looks really long because I have different attributes for every day of the week using multiple checkboxes

Generated YAML seems to be incompatbile with syck

Not sure whether this is a syck issue or an ice_cube issue.

Given the simple schedule_yaml of
"---\n:start_date: 2011-08-09 14:52:14.597283858 +02:00\n:rrules:\n- :rule_type: IceCube::WeeklyRule\n :interval: 1\n :until: !!null \n :count: !!null \n :validations:\n :day:\n - 1\n - 2\n - 3\n - 4\n - 5\n:exrules: []\n:rdates: []\n:exdates: []\n:duration: !!null \n:end_time: !!null \n"

syck chokes with an error of
NoMethodError: undefined method <' for #<Syck::PrivateType:0xcd3078c @type_id="null", @value=""> from /home/nl/.rvm/gems/ruby-1.9.2-p180@phonostar_app/gems/ice_cube-0.6.13/lib/ice_cube/schedule.rb:17:ininitialize'
from /home/nl/.rvm/gems/ruby-1.9.2-p180@phonostar_app/gems/ice_cube-0.6.13/lib/ice_cube/schedule.rb:61:in new' from /home/nl/.rvm/gems/ruby-1.9.2-p180@phonostar_app/gems/ice_cube-0.6.13/lib/ice_cube/schedule.rb:61:infrom_hash'
from /home/nl/.rvm/gems/ruby-1.9.2-p180@phonostar_app/gems/ice_cube-0.6.13/lib/ice_cube/schedule.rb:71:in `from_yaml'

I solved the problem by using psych to parse the schedule, but syck is apparently the default now in rails?

Weekly Rule

Hello,

I'm using ice_cube with RoR but I can't seem to get weekly rules to work. I've stripped out all the user input and hard coded the inputs and here is the code:

rule_inst = IceCube::Rule.weekly(1).day(4)
st = DateTime.new(2011,12,1,18,0,0)
fin = DateTime.new(2012,1,19,18,0,0)
schedule = IceCube::Schedule.new(st, :end_time => fin)
schedule.add_recurrence_rule rule_inst

occurrences = schedule.all_occurrences

But occurrences only gets filled with an array of 1 element pointing to the time/date for the start time. What I would expect is the dates of every Thursday between the start and end date.

Change start_time

It's not possible to change the start_time after the schedule is created.

"Daily in May" example fails.

Trying out ice_cube 0.6.14 example for daily occurrences within a given month (May) as shown on the http://seejohncode.com/ice_cube/ page.

Ruby 1.9.2-p290

As I understand it, Rule.daily.month_of_year(:may) produces a rule for an occurrence on every day in may from the schedule's start_date into end of time. However, the recurrence seems to produce events on ONE day (same as start_date's day) in the month specified for every upcoming year.

This differs from the documentation, and differs from the "Daily in May" schedule.to_s output.

$ irb
ruby-1.9.2-p290 :001 > require 'ice_cube'
 => true 
ruby-1.9.2-p290 :002 > require 'ice_cube/version'
 => true 
ruby-1.9.2-p290 :003 > IceCube::VERSION
 => "0.6.14" 
ruby-1.9.2-p290 :004 > include IceCube
 => Object 
ruby-1.9.2-p290 :005 > # Create a schedule for every day in May
ruby-1.9.2-p290 :006 >   schedule = Schedule.new(Time.now)
 =>  
ruby-1.9.2-p290 :007 > schedule.add_recurrence_rule Rule.daily.month_of_year(:may)
 => [#<IceCube::RuleOccurrence:0x007fbc891a8108 @rule=Daily in May, @start_date=2011-09-14 21:34:28 -0700, @end_time=nil, @date=nil, @index=0>] 
ruby-1.9.2-p290 :008 > # Does it occur at a certain time?
ruby-1.9.2-p290 :009 >   schedule.occurs_at?(Time.local(2010, 11, 1)) # false
 => false 
ruby-1.9.2-p290 :010 > # Does it occur on a certain date?
ruby-1.9.2-p290 :011 >   schedule.occurs_on?(Date.today)
 => false 
ruby-1.9.2-p290 :012 > Date.today
 => #<Date: 2011-09-14 (4911637/2,0,2299161)> 
ruby-1.9.2-p290 :013 > # All of the occurrences between two Times
ruby-1.9.2-p290 :014 >   schedule.occurrences_between(Time.local(2010, 1, 1), Time.local(2010, 12, 1))
 => [] 
ruby-1.9.2-p290 :015 > 
ruby-1.9.2-p290 :016 >   schedule.occurrences_between(Time.local(2010, 1, 1), Time.local(2013, 12, 1))
 => [2012-05-14 21:34:28 -0700, 2013-05-14 21:34:28 -0700] 
ruby-1.9.2-p290 :017 > 
ruby-1.9.2-p290 :018 >   schedule.first(10) 
 => [2012-05-14 21:34:28 -0700, 2013-05-14 21:34:28 -0700, 2014-05-14 21:34:28 -0700, 2015-05-14 21:34:28 -0700, 2016-05-14 21:34:28 -0700, 2017-05-14 21:34:28 -0700, 2018-05-14 21:34:28 -0700, 2019-05-14 21:34:28 -0700, 2020-05-14 21:34:28 -0700, 2021-05-14 21:34:28 -0700] 
ruby-1.9.2-p290 :019 > 
ruby-1.9.2-p290 :020 >   schedule.to_s
 => "Daily in May" 
ruby-1.9.2-p290 :021 >

day_of_week is broken under some circumstances

Every so often, it skips dates for no reason. Example:

ruby-1.9.2-p290 :007 > t = Time.local 2011, 8, 1

Then

ruby-1.9.2-p290 :022 > s = Schedule.new(t)
=>
ruby-1.9.2-p290 :023 > s.rrule Rule.monthly.day_of_week(:monday => [1])
=> [#<IceCube::RuleOccurrence:0x00000002c1a2f8 @rule=Monthly on the 1st Monday, @start_date=2011-08-01 00:00:00 -0500, @end_time=nil, @Date=nil, @Index=0>]
ruby-1.9.2-p290 :024 > s.first 10
=> [2011-08-01 00:00:00 -0500, 2011-09-05 00:00:00 -0500, 2011-10-03 00:00:00 -0500, 2011-12-05 00:00:00 -0600, 2012-01-02 00:00:00 -0600, 2012-02-06 00:00:00 -0600, 2012-03-05 00:00:00 -0600, 2012-04-02 00:00:00 -0500, 2012-05-07 00:00:00 -0500, 2012-06-04 00:00:00 -0500]

We've skipped over Nov. 7, 2011

Now:

ruby-1.9.2-p290 :025 > s = Schedule.new(t)
=>
ruby-1.9.2-p290 :026 > s.rrule Rule.monthly.day_of_week(:tuesday => [1])
=> [#<IceCube::RuleOccurrence:0x00000002ab48c8 @rule=Monthly on the 1st Tuesday, @start_date=2011-08-01 00:00:00 -0500, @end_time=nil, @Date=nil, @Index=0>]
ruby-1.9.2-p290 :027 > s.first 10
=> [2011-08-02 00:00:00 -0500, 2011-09-06 00:00:00 -0500, 2011-10-04 00:00:00 -0500, 2011-11-01 00:00:00 -0500, 2012-01-03 00:00:00 -0600, 2012-02-07 00:00:00 -0600, 2012-03-06 00:00:00 -0600, 2012-04-03 00:00:00 -0500, 2012-05-01 00:00:00 -0500, 2012-06-05 00:00:00 -0500]

We've skipped Dec. 6, 2011.

What's the best approach on Rule creation?

Hello! I've being trying ice_cube for a couple days now, and I got stuck on what would be best when defining a rule...

Imaging I need to define the schedule a dentist usually works. In plain text might be something like:

"Every Monday, Tuesday and Friday from 8:00 to 12:00, each session lasting 60 minutes"

I came up with a kinda weird approach, and I'd be glad to get some feedback on: :)

schedule = IceCube::Schedule.new Time.now
schedule.duration  = 60
schedule.rrule IceCube::Rule.minutely(60).day(:monday, :tuesday, :friday).hour_of_day(8, 9, 10, 11)

This way, I can define which slots of time will be available...

Thanks!

Every month on the 30th day

I'm trying to do this:

schedule.add_recurrence_rule Rule.monthly.day_of_month(30)

without it skipping February (and just using the last day).
Is it possible? I can't see anything in the iCal specification to cover this type of thing.

I know it's not really an issue, but just wondered if there is a workaround?

Adding multiple rules

I am trying to add a rule to occur every week spending on what the user selected (e.g. every Monday, Tuesday and Thursday). However if add multiple rules I get the following error

undefined method `reset' for nil:NilClass

in line where event.schedule.each_occurrence { |t| ... }

I don't see a way to add a rule like the following

list = [:monday, :tuesday, :thursday]
schedule.add_recurrence_rule Rule.weekly(1).day(list)

Infinite loop in 0.7.4

I upgraded from version 0.6.14 to 0.7.4, then I noticed a infinite loop while running my specs. Digging more deep I found where the infinite loop was taking place. I'll paste some debug prints and a backtrace. I hope this will help you guys to fix the problem. One thing that may be worth noting is that I live in Brazil (GMT-03:00, GMT-02:00 at the time of the tests due summer time)

I downgraded to 0.6.14 and it worked.

OS: Mac OSX Lion
Ruby: 1.9.2

The code below was executed using rails console

sc = IceCube::Schedule.new Time.now, :end_time => 4.years.from_now.end_of_year
sc.add_recurrence_rule :monthly
sc.occurrences 2.years.from_now

Debugging prints and backtrace

clearing
2013-10-19 23:00:00 -0300
clearing
2013-10-19 23:00:00 -0300
clearing
2013-10-19 23:00:00 -0300
clearing
2013-10-19 23:00:00 -0300
clearing
2013-10-19 23:00:00 -0300
clearing
2013-10-19 23:00:00 -0300
clearing
2013-10-19 23:00:00 -0300
clearing
2013-10-19 23:00:00 -0300
clearing
2013-10-19 23:00:00 -0300
clearing
2013-10-19 23:00:00 -0300
clearing
2013-10-19 23:00:00 -0300
clearing
2013-10-19 23:00:00 -0300
clearing
2013-10-19 23:00:00 -0300
clearing
2013-10-19 23:00:00 -0300
clearing
2013-10-19 23:00:00 -0300
clearing
2013-10-19 23:00:00 -0300
clearing
2013-10-19 23:00:00 -0300
clearing
2013-10-19 23:00:00 -0300
clearing
2013-10-19 23:00:00 -0300
clearing
2013-10-19 23:00:00 -0300^CIRB::Abort: abort then interrupt!!
from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/ice_cube-0.7.4/lib/ice_cube/validated_rule.rb:41:in call' from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/ice_cube-0.7.4/lib/ice_cube/validated_rule.rb:41:inwrite'
from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/ice_cube-0.7.4/lib/ice_cube/validated_rule.rb:41:in puts' from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/ice_cube-0.7.4/lib/ice_cube/validated_rule.rb:41:inputs'
from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/ice_cube-0.7.4/lib/ice_cube/validated_rule.rb:41:in block (2 levels) in next_time' from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/ice_cube-0.7.4/lib/ice_cube/validated_rule.rb:25:ineach'
from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/ice_cube-0.7.4/lib/ice_cube/validated_rule.rb:25:in all?' from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/ice_cube-0.7.4/lib/ice_cube/validated_rule.rb:25:inblock in next_time'
from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/ice_cube-0.7.4/lib/ice_cube/validated_rule.rb:24:in loop' from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/ice_cube-0.7.4/lib/ice_cube/validated_rule.rb:24:innext_time'
from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/ice_cube-0.7.4/lib/ice_cube/schedule.rb:302:in block (2 levels) in next_time' from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/ice_cube-0.7.4/lib/ice_cube/schedule.rb:300:ineach'
from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/ice_cube-0.7.4/lib/ice_cube/schedule.rb:300:in block in next_time' from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/ice_cube-0.7.4/lib/ice_cube/schedule.rb:299:inloop'
from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/ice_cube-0.7.4/lib/ice_cube/schedule.rb:299:in next_time' from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/ice_cube-0.7.4/lib/ice_cube/schedule.rb:285:inblock in find_occurrences'
from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/ice_cube-0.7.4/lib/ice_cube/schedule.rb:284:in loop' from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/ice_cube-0.7.4/lib/ice_cube/schedule.rb:284:infind_occurrences'
from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/ice_cube-0.7.4/lib/ice_cube/schedule.rb:123:in occurrences' from (irb):4 from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/railties-3.0.11/lib/rails/commands/console.rb:44:instart'
from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/railties-3.0.11/lib/rails/commands/console.rb:8:in start' from /Users/esdrasmayrink/.rvm/gems/ruby-1.9.2-p290@organizze/gems/railties-3.0.11/lib/rails/commands.rb:23:in<top (required)>'
from script/rails:6:in require' from script/rails:6:in

'ruby-1.9.2-p290 :005 > exit

Some rules hang the computer

I have a rule that is causing my computer to hang. CPU usage goes up really high and I have yet to find the patience to wait long enough for this to return, assuming it returns at all.
Here is how to reproduce:

ruby-1.9.2-p290 :014 >   rule = IceCube::Rule.from_yaml "--- \n:interval: 1\n:count: \n:rule_type: IceCube::MonthlyRule\n:until: \n:validations: \n  :day: \n  - 5\n  :hour_of_day: \n  - 14\n  :second_of_minute: \n  - 0\n  :day_of_month: \n  - 13\n  :minute_of_hour: \n  - 0\n  :month_of_year: \n  - 10\n" 
 => Monthly on Fridays on the 14th hour of the day on the 0th second of the minute on the 13th day of the month on the 0th minute of the hour in October 
ruby-1.9.2-p290 :015 > schedule = IceCube::Schedule.new(Time.now)
 =>  
ruby-1.9.2-p290 :016 > schedule.add_recurrence_rule(rule)
 => [#<IceCube::RuleOccurrence:0x00000003937ff8 @rule=Monthly on Fridays on the 14th hour of the day on the 0th second of the minute on the 13th day of the month on the 0th minute of the hour in October, @start_date=2011-12-08 08:54:07 -0500, @end_time=nil, @date=nil, @index=0>] 
ruby-1.9.2-p290 :017 > schedule.first

If you could shed some light on this it would be great.
Thanks.

Daily rules stop working after daylight savings time starts

Daily rules that start in standard time seem to stop generating occurrences after daylight savings time starts. Occurrences seem to resume after daylight savings time ends.

Here is a spec:

--- a/spec/examples/daily_rule_spec.rb
+++ b/spec/examples/daily_rule_spec.rb
@@ -21,5 +21,16 @@ describe DailyRule, 'occurs_on?' do
     dates.size.should == 3
     dates.should == [DAY, DAY + 2 * IceCube::ONE_DAY, DAY + 4 * IceCube::ONE_DAY]
   end
-     
+
+  it 'should produce the correct days spanning daylight savings time' do
+    Time.zone = "Eastern Time (US & Canada)"
+    schedule = Schedule.new(Time.zone.parse("Mar 12 2010 19:00"))
+    schedule.add_recurrence_rule Rule.daily(3)
+    dates = schedule.occurrences(Time.zone.parse("Mar 19 2010"))
+    dates.size.should == 3
+    dates.should == [Time.zone.parse("Mar 12 2010 19:00"),
+                     Time.zone.parse("Mar 15 2010 19:00"),
+                     Time.zone.parse("Mar 18 2010 19:00")]
+  end
+ 
 end

P.S. Sorry if I submitted this multiple times, github is being really strange for me.

Can't set start_date for Schedule

I'm trying to use ice_cube with rails but I think there are some bugs with start_date.
See this code:

> tmp.class
 => IceCube::Schedule 
> tmp
 => Monthly on the 1st day of the month 
> tmp.start_date = Date.parse('2012-05-01')
 => Tue, 01 May 2012 
> tmp.start_date
 => Tue, 01 May 2012 
> tmp.to_hash
 => {:start_date=>nil, :rrules=>[{:validations=>{:day_of_month=>[1]}, :rule_type=>"IceCube::MonthlyRule", :interval=>1}], :exrules=>[], :rdates=>[], :exdates=>[]}
> 
> 
> tmp.start_date = DateTime.civil(2012,05,11)
 => Fri, 11 May 2012 00:00:00 +0000 
> tmp.start_time
 => Fri, 11 May 2012 00:00:00 +0000 
> tmp.to_hash
 => {:start_date=>nil, :rrules=>[{:validations=>{:day_of_month=>[1]}, :rule_type=>"IceCube::MonthlyRule", :interval=>1}], :exrules=>[], :rdates=>[], :exdates=>[]}
> 
> 
> tmp.start_date = Time.now
 => 2012-01-29 18:18:53 +0100 
> tmp.start_time
 => 2012-01-29 18:18:53 +0100 
> tmp.to_hash
 => {:start_date=>2012-01-29 18:18:53 +0100, :rrules=>[{:validations=>{:day_of_month=>[1]}, :rule_type=>"IceCube::MonthlyRule", :interval=>1}], :exrules=>[], :rdates=>[], :exdates=>[]}

It seems to understand only DateTime and only with a specific format, but I can't understand which. I'm trying to set start_date from a form only setting the date (not time) but I'm not able to save this attribute...

differences between occurrences, and occurrences_between

This works as expected, by missing out the exception date...

schedule = IceCube::Schedule.new(Time.now.beginning_of_day)
schedule.add_recurrence_rule(IceCube::Rule.daily)
schedule.add_exception_date(Time.now.beginning_of_day + 1.day)
=> 2012-02-27 00:00:00 +0000 
schedule.occurrences(Time.now + 6.days)
=> [2012-02-26 00:00:00 +0000, 2012-02-28 00:00:00 +0000, 2012-02-29 00:00:00 +0000, 2012-03-01 00:00:00 +0000, 2012-03-02 00:00:00 +0000, 2012-03-03 00:00:00 +0000] 

but using occurrences_between still shows the exception date...

schedule.occurrences_between(Time.now, Time.now + 6.days) 
=> [2012-02-27 00:00:00 +0000, 2012-02-28 00:00:00 +0000, 2012-02-29 00:00:00 +0000, 2012-03-01 00:00:00 +0000, 2012-03-02 00:00:00 +0000, 2012-03-03 00:00:00 +0000] 

Psych on Heroku

After updating ice_cube to 0.7.6 I'm getting the following error in production (Heroku):

no such file to load -- --- 
:start_date: 2012-01-20 20:00:00 +00:00
:rrules: 
- :rule_type: IceCube::WeeklyRule
[… YAML CONTINUES …]

vendor/bundle/ruby/1.9.1/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:234:in `load'

I've tracked this problem down on the ice_cube side to https://github.com/seejohnrun/ice_cube/blob/master/lib/ice_cube/schedule.rb#L261 . It seems that in production Psych is used as YAML parser and tries to load a file rather than accepting the YAML as string.

It seems something called Psych is defined, but it's #load method tries to load a file.

I got around this by explicitly defining a gem dependency gem 'psych' for production.

I'm assuming that this is not necessarily a ice_cube issue, but maybe something could be done to secure the situation?

occurs_on?

schedule
=> Weekly

schedule.start_date
=> 2012-01-07 00:00:00 +1300

test_date = Date.parse('2011-01-06')
=> Thu, 06 Jan 2011

schedule.occurs_on?( test_date.to_time )
=> false

schedule.occurs_on?( test_date )
=> true

I found the last result to be unexpected. Will convert argument to time for now but thought this might be a bug. Thanks.

Complex rules look funny in to_s

I'm just trying to do a rule for 'Weekly on Wednesdays at 11:00 am'

For example:

schedule.add_recurrence_rule Rule.weekly.day(:wednesday).hour_of_day(11).minute_of_hour(0).second_of_minute(0)

Outputs:
Weekly on the 0th minute of the hour on Wednesdays on the 0th second of the minute on the 11st hour of the day

Is there a simpler way to do this rule?

Remove Occurences and Dates from Schedule

I am writing a small calendar app to plan reoccuring events. In it you can edit the Events and add/remove reoccurence rules and/or dates. Do I have to rebuild a new schedule object when I try to delete a rule? Or is there an official way to remove a rule?

undefined method `dump' for Psych:Module

I'm getting this error on heroku, any idea where this might come from? I'm using version 0.7.6

undefined method `dump' for Psych:Module
 vendor/bundle/ruby/1.9.1/gems/ice_cube-0.7.6/lib/ice_cube/schedule.rb:256:in `to_yaml'

Thanks!

INTERVAL not included in to_ical method

The Validations::DailyInterval, Validations::MonthlyInterval, … modules don't include the "INTERVAL" property in their build_ical method, simply ignoring it when building the iCalendar compliant rule.

IceCube::Rule.daily(3).count(5).to_ical

=> "FREQ=DAILY;COUNT=5"

Should be:

=> "FREQ=DAILY;COUNT=5;INTERVAL=3"

Exception Rule Start Date

I will take a look at the code myself but I was wondering how hard it difficult you think it would be add start dates to exception rules. And where might be the best place to put them.

The reason I am asking is because I need to have recurring schedules with block of days where the schedule is 'paused'. Thought the best way for this would be add an exception rule with a start and end date. Any suggestions?

next_occurrences / next_occurrence broken with exception dates

Given the simple rule of "Weekly on Mondays, Tuesdays, Wednesdays, Thursdays, and Fridays / not on December 25, 2011 / not on December 26, 2011", calling
schedule.next_occurrences(3, Time.new('2011', '12', '24')) +0100] returns [2011-12-27 00:00:00 +0100, 2011-12-28 00:00:00]

Much worse: schedule.next_occurrence Time.new('2011', '12', '24') returns nil

What I think happens in find_occurrences when you call next_occurrences(3):

  1. The next 3 matching dates are calculated
  2. The exception dates are calculated
  3. The exception dates are subtracted from the matching dates

What I think should happen:

  1. The exception dates are calculated
  2. The next (3 + number_of_exception_dates) matching dates are calculated
  3. The exception dates are subtracted from the matching dates

Sadly, I can't figure out how to code this well.

What is the best approach to identify the Schedule ?

Hey,
i would like to identify the details of an schedule. e.g:

i have the schedule for an event: event.schedule

"Every 3 months on the 10th day of the month"

represented by the hash:

  {
   :start_date=>2012-02-06 10:37:04 +0100, 
   :rrules=>[{
     :validations=>{
       :day_of_month=>[10]}, 
       :rule_type=>"IceCube::MonthlyRule", 
       :interval=>3
    }], 
    :exrules=>[], :rdates=>[], :exdates=>[] 
  }

to set the specific form elements (dropdown, checkbox) i need to evaluate the specific rules. e.g. for

  event.schedule.interval 

i would expect

  IceCube::MonthlyRule

i did not found any methods in the source, does somebody did sth. similar ? My approach would be to parse the hash and extract every rule...

kind of a double post: http://stackoverflow.com/questions/9158421/identify-the-ice-cube-schedule

Schedule#occurrences seems to take linearly more time in the future

I did some testing and it seems that if I increase the start time and call schedule.occurrences, the time taken to compute raises linearly.

Is it a known issue? Are there known work-arounds in ice_cube itself to deal with this maybe? (apart from patching in some way the library, which I suspect could be fairly difficult :-).

If there is no solution I can still do some background processing and cache the results in the database on the required timeframe.

Any hint is most welcome!

occurrences_between doesn't work as expected with a duration

Here's failing spec that I think should pass. Basically, if the occurrence starts before the start time you pass to occurrences, but the occurrence is occurring after that start time, then I think the start time of the occurrence should be returned from occurrences_between, but it is not.

From 4ccc7c683a9845dcf0c48102e63f5ee4afe68bda Mon Sep 17 00:00:00 2001
From: Paul Barry <[email protected]>
Date: Wed, 23 Jun 2010 11:59:56 -0400
Subject: [PATCH] Added failing spec for using occurrences_between with a duration

---
 spec/examples/ice_cube_spec.rb |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/spec/examples/ice_cube_spec.rb b/spec/examples/ice_cube_spec.rb
index 8a74087..581baeb 100644
--- a/spec/examples/ice_cube_spec.rb
+++ b/spec/examples/ice_cube_spec.rb
@@ -324,6 +324,14 @@ describe Schedule, 'occurs_on?' do
     dates.should == [start_time + ONE_DAY * 2, start_time + ONE_DAY * 3, start_time + ONE_DAY * 4]
   end

+  it 'should be able to find occurrences between two dates based on duration' do
+    start_time = Time.local(2010, 6, 29, 10, 0, 0)
+    schedule = Schedule.new(start_time, :duration => ONE_DAY * 3)
+    schedule.add_recurrence_rule Rule.monthly.day_of_week :tuesday => [-1]
+    dates = schedule.occurrences_between(Time.local(2010, 7, 1, 0, 0, 0), Time.local(2010, 8, 1, 0, 0, 0))
+    dates.should == [Time.local(2010, 6, 29, 10, 0, 0), Time.local(2010, 7, 27, 10, 0, 0)]
+  end
+
   it 'should be able to determine whether a given rule falls on a Date (rather than a time) - happy path' do
     start_time = Time.local(2010, 7, 2, 10, 0, 0)
     schedule = Schedule.new(start_time)
-- 
1.7.1

Excluding times from weekly rule not working

I have a schedule set up like so:

IceCube::Schedule.new(Time.zone.local(2011, 6, 14, 14, 0, 0)).tap do |schedule|
  schedule.add_recurrence_rule IceCube::Rule.weekly.day(:tuesday, :thursday)
  schedule.add_exception_time Time.zone.local(2011, 12, 27, 14, 0, 0)
end

But it doesn't seem to respect the exception time, and insists the next occurence is exactly the same time as the exception.

Shorter summarized rule strings when possible

First of all, thanks for the great gem!

I want to add some summary methods to the string outputs for shortening the rules. To start with, I would add "Weekdays", and "Weekends". I was planning to do this in the DayValidation, and WeeklyRule classes. Any thoughts?

Forrest

schedule.conflicts_with?(other_schedule)

weekdays_schedule.conflicts_with?(sunday_only_schedule) => false
weekdays_schedule.conflicts_with?(tuesday_only_schedule) => true

Would such a method be possible? Should I test if schedules conflict with each other manually? Thanks

Conflicts_with? feature

It would be nice to have a method called conflicts_with? which would say if two schedules are conflicting (ie overlap)

example:

Schedule1 = Every 2 week on sundays and saturdays

and

Schedule2 =  Every month on the first day

gives

> schedule1.conflicts_with?(schedule2)
=> true

Please let me know if this already exists, Thanks!
ps: also if you have an idea what would be the best way to implement this, also let me know. If I have time I might just give it a try.

Bug with interval and yaml

In v.0.7.1 after save/restore from yaml the information about interval become incorrect in #occurrences_between

r = Rule.daily(3)
s = Schedule.new(Time.now)
s.add_recurrence_rule(r)
s.occurrences_between(Time.local(2011, 12, 1), Time.local(2011, 12, 31))  # This works correctly with interval of 3 days

yaml = s.to_yaml
sbug = Schedule.from_yaml(yaml)

sbug.occurrences_between(Time.local(2011, 12, 1), Time.local(2011, 12, 31))  # Bug: now every day

sbug.to_s  # However this shows "Every 3 days"

occurrences_between seem break with count rule

Rule with "count" seem incompatible with occurrences_beetween function when you ask with date after the last occurrence date.

This test actually break at the line 4. I think it shouldn't :

schedule = IceCube::Schedule.new(Time.now)
schedule.add_recurrence_rule(IceCube::Rule.daily.count(5))
schedule.occurrences_between(Time.now, Time.now + 7.days).count.should == 5
schedule.occurrences_between(Time.now + 7.days, Time.now + 14.days).count.should == 0

Intervals and how they work

Hi John,

This isn't necessarily an issue, just wanted to know what your thinking is behind intervals.

It looks like when you do a fortnightly rule, like:
IceCube::Rule.weekly(2).day(2) #recurring every other tuesday.

The weeks that the occurrences recur on is based on the week number in the year, rather than the number of weeks from the start date of the schedule.

For example, if my schedule starts on 2010-01-05, the first 3 occurences are:
2010-01-12,
2010-01-26
2010-02-09

where I would have expected:
2010-01-05
2010-01-19
2010-02-02
(i.e. fortnightly from the start date).

I appreciate either behaviour makes sense depending on the particular application, but is the former behaviour what you expect?

Hope I have made sense!

Incidentally, schedule.first(n) with a fortnightly rule gives you 5 rather than 10 occurences (i.e. the first 10 weeks of occurences, rather than the first 10 occurences).

Cheers,
Philip Roberts

0.6.12: Changing start_date doesn't change internal use of start_date

When the start date is changed, the Schedule instance seems to use the old start_date when calculating occurring_at?(). Rebuilding the object "x = Schedule.from_hash(x.to_hash)" clears the issue and uses the new start date internally. For my test case "occurring_at?()" goes from a 7 second calculation to about a millisecond (depending on cpu capability of course).

Thanks for your efforts in creating and maintaining this library!

As a side issue, and not a bug per se, when a start_date is significantly before a time being tested, the calculation can take a long time. However, I believe the code only needs to test in the range ("t - self.duration" through time t) to determine if occurring_at?(t) is true. Duration would default to one day if not specified (?).

A simple test program:
ruby 1.8.7 (2010-12-23 patchlevel 330) [i686-linux]
ice_cube (0.6.12)

#!/usr/bin/ruby
require 'rubygems'
require 'ice_cube'

tbegin = Time.local(0,0,0,10,12,1970,nil,nil,true,'CDT')
t      = Time.local(0,1,1,10, 8,2011,nil,nil,true,'CDT')
tend   = Time.local(0,0,0,10,12,2037,nil,nil,true,'CDT')

schedule  = IceCube::Schedule.new(tbegin, :end_time => tend, :duration => (60*60*24))

days = [0,1,2,4,5,6]
rule1 = IceCube::Rule.weekly.day(*days)

schedule.add_recurrence_rule(rule1)

# test time to calculate occurring_at?() with starting date in 1970
t_a0 = Time.now
occurs_a = schedule.occurring_at?(t)
t_a1 = Time.now

# change the start date to just be one day ahead
schedule.start_date = t - (60*60*24)

# test time to calculate occurring_at?() with
# starting date in 2011 just by changing 'start_date' value
t_b0 = Time.now
occurs_b = schedule.occurring_at?(t)
t_b1 = Time.now

# convert the schedule to a hash and then rebuild it from the same hash
schedule2 = IceCube::Schedule.from_hash(schedule.to_hash)
# schedule2 should be exact logical copy of schedule

# Test how fast occurring_at?() is calculated now.
t_c0 = Time.now
occurs_c = schedule2.occurring_at?(t)
t_c1 = Time.now

puts "Test occurring_at? start_date in 1970:    t_a_delta=#{t_a1-t_a0}" # slow
puts "start_date set to 2011 using method:      t_b_delta=#{t_b1-t_b0}" # slow
puts "to_hash() passed directly to from_hash(): t_c_delta=#{t_c1-t_c0}" # fast

My results:

[root@conf1 lance]# ./icecube
Test occurring_at? start_date in 1970: t_a_delta=11.53168
start_date set to 2011 using method: t_b_delta=12.15053
to_hash() passed directly to from_hash(): t_c_delta=0.001712

Monthly day of week rules shift by an hour over DST boundaries

Monthly day of week rules like:
Rule.monthly.day_of_week(:tuesday => [3])

Are shifting by an hour when they recur over daylight savings time boundaries.

Spec:
--- a/spec/examples/dst_spec.rb
+++ b/spec/examples/dst_spec.rb
@@ -210,6 +210,13 @@ describe Schedule, 'occurs_on?' do
schedule.first(3).should == [Time.local(2010, 3, 12, 19, 0, 0), Time.local(2010, 5, 12, 19, 0, 0), Time.local(2010, 7, 12, 19, 0, 0)]
end

+  it "local - should make dates on monthly (day of week) inverval over dst" do
+    start_date = Time.local(2010, 3, 7, 12, 0, 0)
+    schedule = Schedule.new(start_date)
+    schedule.add_recurrence_rule Rule.monthly.day_of_week(:sunday => [1])
+    schedule.first(3).should == [Time.local(2010, 3, 7, 12, 0, 0), Time.local(2010, 4, 4, 12, 0, 0), Time.local(2010, 5, 2, 12, 0, 0)]
+  end
+
   it 'local - should make dates on yearly interval over dst - github issue 4' do
     start_date = Time.local(2010, 3, 12, 19, 0, 0)
     schedule = Schedule.new(start_date)

from_ical

Is there a way to parse a ical event ? (especially the RRULE part)

For example I'd glad to make this :

schedule.from_ical "DTSTART:20111216T090000Z;RRULE:FREQ=YEARLY;BYMONTHDAY=6;BYMONTH=11;"

occuring_at? not working

ruby-1.9.2-p290 :001 > schedule = IceCube::Schedule.new(Time.now, :duration => 36000)
 =>  
ruby-1.9.2-p290 :002 > schedule.occurring_at?(Time.now + 1800)
 => false 
ruby-1.9.2-p290 :003 > 

The above is the same as the one in the ReadMe file
Shouldn't this be true

Infinite loop on method occurring_at?

Hello,

Small test to show a loop bug on method occurring_at? (or I am missing something stupid to make it work right)

Schedule definition

Every 60 minutes on Thursdays on the 14th, 15th, and 16th hours of the day on the 0th minute of the hour

The yaml code

---
:start_date: 2011-11-16 11:31:58.441381000 -02:00
:rrules:
- :rule_type: IceCube::MinutelyRule
  :interval: 60
  :until: !!null 
  :count: !!null 
  :validations:
    :day:
    - 4
    :hour_of_day:
    - 14
    - 15
    - 16
    :minute_of_hour:
    - 0
:exrules: []
:rdates: []
:exdates: []
:duration: 3600
:end_time: !!null 

When running:

schedule.occurring_at? Time.new(2011,11,17,15,30)

It never stops... :S

Any ideas?!

Cheers

Infinite loop

This will produce an infinite loop, at least it does for me on Ruby 1.8.6

require "rubygems"
require "ice_cube"
require "time"

schedule = IceCube::Schedule.new(Time.parse("2010-08-30"))
schedule.add_recurrence_rule IceCube::Rule.monthly(6)
puts schedule.occurrences_between(Time.parse("2010-07-01"), Time.parse("2010-09-01"))

Localization for rule descriptions

Hi!

I could not find any specs about how to localize rule string result. I need to localize for example rule string "Weekly, on tuesdays".

Creating daily rule error message

I'm having trouble listing daily occurrences with the following code:

require 'ice_cube'

start = Time.local(2011, 10, 21)
schedule = IceCube::Schedule.new(start)
schedule.rrule IceCube::Rule.daily

schedule.occurrences_between(start, Time.local(2012, 12, 1)).each do |o|
  p o
end```

This returns this error message:

/Library/Ruby/Gems/1.8/gems/ice_cube-0.6.14/lib/ice_cube/rules/daily_rule.rb:9:in `in_interval?': private method`to_date' called for Fri Oct 21 00:00:00 -0700 2011:Time (NoMethodError)
    from /Library/Ruby/Gems/1.8/gems/ice_cube-0.6.14/lib/ice_cube/rule_occurrence.rb:61:in `succ'
    from /Library/Ruby/Gems/1.8/gems/ice_cube-0.6.14/lib/ice_cube/rule_occurrence.rb:79:in`find_occurrences'
    from /Library/Ruby/Gems/1.8/gems/ice_cube-0.6.14/lib/ice_cube/rule_occurrence.rb:15:in `between'
    from /Library/Ruby/Gems/1.8/gems/ice_cube-0.6.14/lib/ice_cube/schedule.rb:241:in`occurrences_between'
    from /Library/Ruby/Gems/1.8/gems/ice_cube-0.6.14/lib/ice_cube/schedule.rb:240:in `each'
    from /Library/Ruby/Gems/1.8/gems/ice_cube-0.6.14/lib/ice_cube/schedule.rb:240:in`occurrences_between'
    from cube.rb:8

Change duration

Currently I can only set the duration of an event in the initializer. It would be great if I could change it afterwards, too.

More examples

Hello,

I find the syntax of your library to be very nice and readable. However, I'm more interested to know what kinds of things can be done with your library. For example, I'm working on displaying a weekly schedule of activities. I will need to create a form for creating the recurrence rules. The activities occur on the same day(s) every week, so there is no need for me to save an actual date in the database. I'm more concerned with saving the time of day, and day of the week. So I am wondering if your library can help we with that. So far I'm just saving the day as a number (0-6) and the time as a string (i.e. 8:00am), but I'm looking for a more elegant solution.

Can your library help me with that? What other use cases could this library be used for?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.