GithubHelp home page GithubHelp logo

icalendar-recurrence's Introduction

iCalendar Recurrence Build Status Code Climate

Adds event recurrence to the icalendar gem. This is helpful in cases where you'd like to parse an ICS and generate a series of event occurrences.

Install

Note: Works with 2.0.0beta.1 (or newer) icalendar gem. If you're using icalendar <=1.5.4, take a look at the new code before you switch over.

gem "icalendar-recurrence"

and run bundle install from your shell.

Usage

Show occurrences of event between dates

require 'date' # for parse method
require 'icalendar/recurrence'

calendars = Icalendar::Calendar.parse(File.read(path_to_ics)) # parse an ICS file
event = Array(calendars).first.events.first # retrieve the first event
event.occurrences_between(Date.parse("2014-01-01"), Date.parse("2014-02-01")) # get all occurrence for one month

Get all occurrences

To get all occurrences you can use all_occurrences. This only works when you have specified an ending using until or count in your RRULE.

Working with occurrences

An event occurrence is a simple struct object with start_time and end_time methods.

occurrence.start_time # => 2014-02-01 00:00:00 -0800
occurrence.end_time   # => 2014-02-02 00:00:00 -0800

Daily event with excluded date (inline ICS example)

require 'date' # for parse method
require 'icalendar/recurrence'

ics_string = <<-EOF
BEGIN:VCALENDAR
X-WR-CALNAME:Test Public
X-WR-CALID:f512e378-050c-4366-809a-ef471ce45b09:101165
PRODID:Zimbra-Calendar-Provider
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
UID:efcb99ae-d540-419c-91fa-42cc2bd9d302
RRULE:FREQ=DAILY;INTERVAL=1
SUMMARY:Every day, except the 28th
DTSTART;VALUE=DATE:20140101
DTEND;VALUE=DATE:20140102
STATUS:CONFIRMED
CLASS:PUBLIC
X-MICROSOFT-CDO-ALLDAYEVENT:TRUE
TRANSP:TRANSPARENT
LAST-MODIFIED:20140113T200625Z
DTSTAMP:20140113T200625Z
SEQUENCE:0
EXDATE;VALUE=DATE:20140128
END:VEVENT
END:VCALENDAR
EOF

# An event that occurs every day, starting January 1, 2014 with one excluded 
# date. January 28, 2014 will not appear in the occurrences.
calendars = Icalendar::Calendar.parse(ics_string)
every_day_except_jan_28 = Array(calendars).first.events.first
puts "Every day except January 28, 2014, occurrences from 2014-01-01 to 2014-02-01:"
puts every_day_except_jan_28.occurrences_between(Date.parse("2014-01-01"), Date.parse("2014-02-01"))

Contributing

  1. Fork it ( http://github.com//icalendar-recurrence/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

icalendar-recurrence's People

Contributors

espen avatar jnraine avatar jon-sully avatar mrdougwright avatar paultyng avatar paulusasol avatar rahearn avatar skoushan avatar stephenbinns avatar va7map avatar warmwaffles 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

icalendar-recurrence's Issues

Handle RDATE as specified in RFC 5545

As the gem extends icalendar, which implements RFC 5545, there are three recurrence properties that must be considered to determine all occurrences of a calendar event.

Expected:

Recurrence properties as specified in 3.8.5 Recurrence Component Properties of RFC 5545 are passed on to ice-cube.
These are:

  • RRULE
  • RDATE
  • EXDATE

Actual:

In Icalendar::Recurrence::Schedule#ice_cube_schedule only RRULE and EXDATE are passed on to ice-cube.

Todo:

  • Add spec for testing EXDATE
  • Add call to IceCube::Schedule#add_recurrence_time (similar as used for EXDATE)

Issues when installing the gem with gemfile

Hi. I just installed icalendar-recurrence today with gemfile:

# frozen_string_literal: true

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

# gem "rails"
gem "icalendar-recurrence"

with

bundle install

and tried to run the example code

require 'date' # for parse method
require 'icalendar/recurrence'

ics_string = <<-EOF
BEGIN:VCALENDAR
X-WR-CALNAME:Test Public
X-WR-CALID:f512e378-050c-4366-809a-ef471ce45b09:101165
PRODID:Zimbra-Calendar-Provider
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
UID:efcb99ae-d540-419c-91fa-42cc2bd9d302
RRULE:FREQ=DAILY;INTERVAL=1
SUMMARY:Every day, except the 28th
DTSTART;VALUE=DATE:20140101
DTEND;VALUE=DATE:20140102
STATUS:CONFIRMED
CLASS:PUBLIC
X-MICROSOFT-CDO-ALLDAYEVENT:TRUE
TRANSP:TRANSPARENT
LAST-MODIFIED:20140113T200625Z
DTSTAMP:20140113T200625Z
SEQUENCE:0
EXDATE;VALUE=DATE:20140128
END:VEVENT
END:VCALENDAR
EOF

# An event that occurs every day, starting January 1, 2014 with one excluded 
# date. January 28, 2014 will not appear in the occurrences.
calendars = Icalendar.parse(ics_string)
every_day_except_jan_28 = Array(calendars).first.events.first
puts "Every day except January 28, 2014, occurrences from 2014-01-01 to 2014-02-01:"
puts every_day_except_jan_28.occurrences_between(Date.parse("2014-01-01"), Date.parse("2014-02-01"))

and I got the following error:

Traceback (most recent call last):
        2: from c:/Users/MSI GF/Desktop/Swinburne/COS10009/Test/calendar.rb:3:in `<main>'
        1: from C:/Ruby27-x64/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
C:/Ruby27-x64/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require': cannot load such file -- icalendar/recurrence (LoadError)
        9: from c:/Users/MSI GF/Desktop/Swinburne/COS10009/Test/calendar.rb:3:in `<main>'
        8: from C:/Ruby27-x64/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:156:in `require'
        7: from C:/Ruby27-x64/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:168:in `rescue in require'
        6: from C:/Ruby27-x64/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:168:in `require'
        5: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/icalendar-recurrence-1.1.3/lib/icalendar/recurrence.rb:6:in `<top (required)>'
        4: from C:/Ruby27-x64/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
        3: from C:/Ruby27-x64/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
        2: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/icalendar-recurrence-1.1.3/lib/icalendar/recurrence/time_util.rb:1:in `<top (required)>'
        1: from C:/Ruby27-x64/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
C:/Ruby27-x64/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require': cannot load such file -- tzinfo (LoadError)
PS C:\Users\MSI GF\Desktop\Swinburne\COS10009\Test>

I tried to create a new ruby bundle going to a different folder and using bundle init, tried importing different files into the code such as icalendar, rubygems, and tried installing icalendar in gemfile but to no avail. What am I doing wrong here?

Do not fail when rrule is not valid

Using invalid RRULE results in undefined local variable or method rrule' for #Icalendar::Recurrence::Schedule..`

Will provide a failing test later.

Failing test

Failures:

  1. Icalendar::Recurrence::TimeUtil timezone_offset handles daylight savings
    Failure/Error: expect(TimeUtil.timezone_offset("America/Los_Angeles", moment: minute_after_clocks_change)).to eq("-08:00")
   expected: "-08:00"
        got: "-07:00"

   (compared using ==)
 # ./spec/lib/time_util_spec.rb:88:in `block (3 levels) in <top (required)>'

Failure to load gem with icalendar 2.1.2

I'm new to ruby, so I could very well be doing something wrong for the gem install or calling the code. Is this expected behavior?

/usr/lib/ruby/2.0.0/rubygems/specification.rb:2007:in `raise_if_conflicts': Unable to activate icalendar-recurrence-0.0.1, because icalendar-2.1.2 conflicts with icalendar (~> 2.0.0.beta.1) (Gem::LoadError)


$ gem query --local | grep -i icalendar
icalendar (2.1.2, 2.0.1)
icalendar-recurrence (0.0.1)

Version number needs bumping

Hiya, please could you bump the version number now that there's a fix for convert_duration_to_seconds? Thanks!

List tzinfo as runtime dependency

Currently, tzinfo is listed as a development dependency.

But from its usage in time_util.rb we can see, it should be a runtime dependency.

This will cause issues, when the gem is used in a plain ruby project, where tzinfo is not required by activesupport for example.

For anyone encountering this issue, you can temporarily fix this by just requiring it alongside this gem yourself:

gem 'icalendar-recurrence'
gem 'tzinfo'

Add all_occurrences

Any reason for the requirement to specify occurrences between dates? How about adding all_occurrences?

`all_occurrences` doesn't honor exdates across daylight savings transitions

It looks like TimeUtil.to_time is forcing everything to be a Time object with offset calculated. That causes issues for honoring exdate that are across DST boundaries. I think that if active support is available on the system then everything passed to ice cube should likely be TimeWithZone objects.

More information and a reproducible test file is at icalendar/icalendar#221

I'll try to submit a PR for this, but it'll likely be a while until I get to it so if anyone else has the time to tackle it go for it.

convert_ice_cube_occurrence should not use "warn"

Currently TZInfo::InvalidTimezoneIdentifier errors are rescued in this method and "warn" is used to output a message. I am using this code in a cron job where I have no influence over the icalendar files I'm processing, and some events have invalid timezone identifiers. The result of this code is that I now get output for each cron run, making the output meaningless. I would rather just handle the errors myself and a way that works for my situation, and I also feel that this would be a good default case here.

The code change would then be to simply remove both the rescue and the warn method. I'd be happy to provide a PR if needed.

Alternatively I suppose the warn could be directed to a logger, or be made optional, but I'm not sure if this if worth the added complexity.

`Time#force_zone` doesn't work

If I type the following In a Rails console:

t = Time.current
t.force_zone("UTC")

I'm getting:

NameError: uninitialized constant Time::TimeUtil

I think that time_util.rb:92 should use the complete namespace: Icalendar::Recurrence::TimeUtil.force_zone(self, tzid).

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.