Giter VIP home page Giter VIP logo

recurring_events's Introduction

Project Status: Active – The project has reached a stable, usable state and is being actively developed. Build Status Coverage Status

RecurringEvents

RecurringEvents is an Elixir library providing recurring events support (duh!).

Documentation

API documentation is available at https://hexdocs.pm/recurring_events

Installation

The package can be installed as:

Add recurring_events to your list of dependencies in mix.exs:

def deps do
  [{:recurring_events, "~> 0.3.0"}]
end

recurring_events's People

Contributors

aptinio avatar kelvinst avatar pbogut avatar voughtdq 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

Watchers

 avatar

recurring_events's Issues

Plans for "Nth Week of Month"?

Love the library - I was trying to do something similar and this is much better than what I was working on. :)

I saw some of the tests are tagged pending (the ones having to do with 1st-week-of-month, last-week-of-month, etc). Are there plans to complete those features?

I poked around the code a little, it seems like maybe a by_week rule that accepted [-5, -4, -3, -2, -1, 1, 2, 3, 4, 5] might be a nice way to add it to the API (freq: :monthly required?)?

Exclude and count/take rules

I wrote this little test:

  test "Test daily frequency with exclude date range" do
    result =
      ~N[2018-01-01 00:00:00]
      |> RR.unfold(%{
        freq: :daily,
        exclude_date: Date.range(~D[2018-01-02], ~D[2018-01-04])
      })

    expect =
      date_expand([
        {{2018, 1, 1}, {0, 0, 0}},
        {{2018, 1, 5}, {0, 0, 0}}
      ])

    assert expect == result |> Enum.take(5)
  end

The test fails, because I am getting 5 dates.
I'll work on adding the feature of handling date ranges.

Creating a struct to hold the RRule and allow composition

Sorry in advance for creating many issues for you... ;)

Right now the provided API is very adhoc, there is mainly 2 entry points depending if you need a stream or not and there is no struct being used to capture the RRule.

I was wondering if the api could evolve in a way where the starting point is the creation of that struct which then can be piped into functions such as:

rrule = RecurringEvents.new(~D[2016-12-07], %{freq: :daily})

RecurringEvents.all(rrule)
RecurringEvents.between(rrule, from, until)
RecurringEvents.take(rrule, 2)
RecurringEvents.to_string(rrule)

of course it would allow composition such as:

RecurringEvents.new(~D[2016-12-07], %{freq: :daily})
|> between(from, until)
|> take(2)

What do you think ?

Support for negative counts

I'd like to add support for negative values for count.

For example:

iex(1)> alias RecurringEvents, as: RR
RecurringEvents
iex(2)> rule = %{date_start: ~D[2020-12-22], by_month_day: 1, freq: :monthly}
%{date_start: ~D[2020-12-22], by_month_day: 1, freq: :monthly}
iex(3)> RR.take(rule, -3)
[[~D[2020-12-22], ~D[2020-12-01], ~D[2020-11-01]]

Any tips on where to look to add support for this?

I started looking in RecurringEvents.Date but I'm wondering if there's a better place to start.

RRULE export

It would be super convenient to be able to have a way to export rules in the text format compatible with RRULE such as:

"FREQ=WEEKLY;DTSTART=20120201T093000Z;INTERVAL=5;UNTIL=20130130T230000Z;BYDAY=MO,FR"

Occurance between dates

Hi there,

Correct me if I am wrong you can only take a specific number of events after a date. Is it possible to query all events between 2 dates?

RRULESET support

Another neat thing to maybe put on the roadmap would be to add support for rruleset. Having a proper struct to capture a rrule is even more important to deal with this.

Support for until rule

Hi,

Awesome library, I was lamenting over the lack of a good RRULE library in Elixir land and stumble upon yours.

Would you consider adding support for the until rule ?

Thanks in advance.

Count dont work with exclude date

%{date_start: ~D[2016-01-01], exclude_date: ~D[2016-01-01], freq: :daily, count: 1, ...}

Will result with 0 dates returned as count is not taking exclude dates into account.

new release?

Hi there, thanks for creating this package!

The latest released version (v0.3.0) contains some warnings on newer Elixir versions:

warning: clauses for the same defp should be grouped together, defp by_set_position/2 was previously defined (lib/recurring_events.ex:160)
  lib/recurring_events.ex:172

These appear to be fixed on master. Any chance you could publish a new version of this package so we can run off a published version? Thanks! 🙏

library does not respect DST boundaries (no timezone awareness)

In the following example:

iex(47)> {:ok, last_time, _} = DateTime.from_iso8601("2018-11-02T12:04:07Z")                                                
{:ok, #<DateTime(2018-11-02T12:04:07Z Etc/UTC)>, 0}

iex(48)> last_time = Timex.Timezone.convert(last_time, "America/Los_Angeles")                                               
#<DateTime(2018-11-02T05:04:07-07:00 America/Los_Angeles)>

iex(49)> RecurringEvents.take(last_time, %{freq: :daily, by_hour: 3, by_minute: 0, by_second: 0}, 5)                        
[#<DateTime(2018-11-02T05:04:07-07:00 America/Los_Angeles)>,
 #<DateTime(2018-11-03T03:00:00-07:00 America/Los_Angeles)>,
 #<DateTime(2018-11-04T03:00:00-07:00 America/Los_Angeles)>,
 #<DateTime(2018-11-05T03:00:00-07:00 America/Los_Angeles)>,
 #<DateTime(2018-11-06T03:00:00-07:00 America/Los_Angeles)>]

I'm starting with a time that's just before the US daylight saving time switch (Sunday Nov 4th), and explicitly setting it to America/Los_Angeles (UTC-7). The correct behavior would, I think, have the following value for Nov 4th:

2018-11-04T03:00:00-08:00 America/Los_Angeles)

The intention of the provided arguments is to have an event that repeats at 3am every day in the given timezone. But since this package has no timezone or DST awareness, it continues with a UTC-7 offset even though the specified zone has switched to UTC-8.

Some invalid values passed to `take/[2,3]` will crash the VM

When giving a negative value to take/[2,3] like this:

RecurringEvents.take(Date.utc_today(), %{by_day: :monday, freq: :weekly}, -1)

The function will consume resources until it crashes the VM.

The same goes for some invalid values, for example:

RecurringEvents.take(Date.utc_today(), %{by_day: :m, freq: :weekly}, 3)

It's probably best to raise an exception when bad values are provided.

The lib does not respect RRULE RFC in case of invalid dates

The RRULE FREQ=MONTHLY;INTERVAL=1;DTSTART=20201031T000000 should actually skip november according to RRULE RFC:

Recurrence rules may generate recurrence instances with an invalid date (e.g., February 30) or nonexistent local time (e.g., 1:30 AM on a day where the local time is moved forward by an hour at 1:00 AM). Such recurrence instances MUST be ignored and MUST NOT be counted as part of the recurrence set.

So basically, this test should pass:

assert RecurringEvents.take(~D[2020-10-31], %{freq: :monthly}, 2) == [~D[2020-10-31], ~D[2020-12-31]]

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.