Giter Site home page Giter Site logo

jakubroztocil / rrule Goto Github PK

View Code? Open in Web Editor NEW
3.2K 60.0 498.0 4.49 MB

JavaScript library for working with recurrence rules for calendar dates as defined in the iCalendar RFC and more.

Home Page: https://jkbrzt.github.io/rrule

License: Other

JavaScript 1.81% TypeScript 98.17% Shell 0.03%
recurrence-rules javascript rrule library calendar icalendar-rfc rfc python-dateutil jakubroztocil typescript

rrule's People

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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rrule's Issues

IE8 support broken in 2.1

Just noticed IE8 support was broken when the underscore dependency was removed. This is fine, it'd just be nice to have the doc's or changelog updated to make that clear.

I downgraded to 2.0.0 and it seems to work fine right now. We will probably added in a ES5 Shim and upgrade shortly.

RFC 5545

Hello,

any plan to support the new RFC? http://tools.ietf.org/html/rfc5545
I need to get result RRULE string to be parsed with a library that uses this more recent version of the specification that differs slightly from the one you are using.

Thanks in advance and keep doing the good work ;)

hmm, what about weekends?

it seems like there is no mention of sunday saturday and option for every weekend?

I guess I could prob do something like after every friday, before its next monday.

Can not set negative values to bysetpos in demo

Additional brackets are needed in Line 175 in demo.js

current:

           } else if (/^by/.test(key)) {
              if (!value instanceof Array) { // <---
                value = value.split(/[,\s]+/);
              }

correct version:

           } else if (/^by/.test(key)) {
              if (!(value instanceof Array)) { // <---
                value = value.split(/[,\s]+/);
              }

Getting More Information about an RRule

Are there some more methods to get some information about an RRule?

I'm in a use case where for example I get an RRule string of:

FREQ=WEEKLY;BYDAY=TU

I'd like to know that this is an RRule.WEEKLY. Also that it occurs on RRule.TU.

Thanks

Consider swapping to lodash

I was pointed here by @bdufresne who's using rrule with classic ASP which apparently works with lodash but not underscore.
With lodash snippets like npl line #84 can be simplified to:

   allWeeks:_.reject(byweekday,'n'),
   someWeeks:_.filter(byweekday,'n')

I also noticed you're using return statements with _.each so ya may dig that with lodash _.each supports exiting early by returning false, unlike Underscore.

Lo-Dash also supports deep _.clone and _.merge which you may find useful and has a considerably faster _.include implementation.

If you'd dig a PR just let me know.

Subsumption of rules

Great library! I was wondering if it's possible to determine whether one rule subsumes another - that is, whether the recurrence of one rule is a superset of the recurrences of another rule. A simple example could be:

Rule 1: Every monday, wednesday and friday of every week at 9:00am.
Rule 2: Every day of every week at 9:00am.

Here Rule 2 subsumes Rule 1.

A naive approach would be to determine what the period of the recurrence is (e.g. Rule 1 is 1 week, Rule 2 is 1 day) and check whether the rule of longer period can have all recurrences reproduced using the rule of shorter period. A better approach is to deterministically compare the rules. I think a rule subsumes another if:

  • freq must be >=
  • interval must be <=
  • dtstart must be equal or earlier
  • byweekday set of days must be equal or a superset

I'm solving a related problem in my app but I might need this later on. If so I might end up implementing it.

Daily Occurance Issue

Please have a look at this rule FREQ=DAILY;COUNT=10;INTERVAL=2;BYDAY=MO,TU,WE,TH,FR.

This should return the dates as
30/10, 1/11, 4/11, 6/11, 8/11, 11/11, 13/11, 15/11, 18/11, 20/11

whereas the library is returning as
30/10, 1/11, 5/11, 7/11 and so on.

As 5/11 falls on Tuesday, why the library missed 4/11.

Any thoughts??

rrule.js path broken in bower.json

When using grunt-bower-install, it puts wrong pathname in index.html to rrule.js, ie. {bower_components}/rrule/rrule.js. I think this can be solved by updating the bower.json file.

Tagging Latest Release

Do you mind tagging your latest release? 1.1.0. Bower has basically only tag support until they release a new master. Thanks.

Only allowing dates after today

If I use this rrule: FREQ=WEEKLY;BYDAY=MO,FR;INTERVAL=5

And do rule.between(moment().subtract('year', 5).toDate(), moment().subtract('year', 4).toDate()); then no dates are found. If instead I do dates in the future such as rule.between(moment().add('year', 4).toDate(), moment().add('year', 5).toDate()); then it works fine.

Suggestion: let the "freq" field contain text to match the RFC 2445 spec

I encountered this issue upon marshalling and unmarshalling data that contains an RRule.

Currently, the rrule.js library expects an integer in the "freq" field.
This works fine, but is incompatible with the RFC 2445 spec.
If I have a recurrence rule specified from another system,
I have to convert the string value of "freq" to the enum integer value used by RRule.
And vice versa when I export such data to another system.
This means I must now support two types for this field.

I have a JSON schema that defines the recurrence according to RFC 2445, as a string enum:

        "freq":    {
            "description": "The frequency.",
            "type": "string",
            "enum": [
                "secondly", "minutely", "hourly", "daily", "weekly", "monthly", "yearly"
            ]
        },

As an experiment, I changed my version of rrule.js to take two fields: "freq" and "freq_n".
"freq" expects a string that matches the spec, and freq_n iis the integer enum value used internally (where the original "freq" was used.)

This seems to work well for me, and solves the marshalling problem.

When select every month on Monday

Hi,

maybe ilt's not a bug, but when i pass

rule =
new RRule({
freq: RRule.MONTHLY,
dtstart: new Date(2013, 11, 31, 15, 0, 0),
byweekday: RRule.MO
})

or in human form : every month on Monday

the resulting is every week on monday.
(the demo show this too)

maybe it's me who misused your library.

thank you for your time and answer
best regard

Recurring events like iCal does

hello there

I've an iCal file containing one recurring event, like this

BEGIN:VEVENT
DTSTART;TZID=Europe/Amsterdam:20110416T193000
DTEND;TZID=Europe/Amsterdam:20110416T203000
RRULE:FREQ=MONTHLY;INTERVAL=2;WKST=MO;BYMONTHDAY=16
DTSTAMP:20131206T093222Z
END:VEVENT

It means that I have an event that:

  • starts on 04/16/2011 at 19.30.00
  • ends on 04/16/2011 at 20.30.00
  • each 2 months
  • on 16th of the month

Can RRule manage this kind of event? How should I build the RRULE string in order to RRule.js can manage this kind of event?

Thanks

DTSTART set as datetime.now() instead of first occurrence

Great work! Just one quick enhancement idea...

Kanzaki writes... "The "DTSTART" property defines the first instance in the recurrence set".

In your code it looks like you set dtstart as now() and then derive the byhour and byminute arrays from dtstart.

I might be missing something here, but it seems like instead of setting DTSTART to the first occurrence it sets dtstart to now(), not adhering to the standard.

link: http://www.kanzaki.com/docs/ical/rrule.html

Parse and transform cron expressions

When you want to use rrule with another library that schedules jobs to run, they use cron expressions. It'd be nice to convert an rrule to a cron expression.

Day repeats when day light savings time starts

Daylight savings time starts on the 28 of September in NZ. It looks like RRules doesn't like this date, and pushes every recurrence back 1 day.

Is there any way to fix this, or work around it?

Tested in (UTC+12:00) Auckland, Wellington Chrome:

new RRule({
    freq: RRule.DAILY,
    dtstart: new Date(2014, 8, 26, 10, 30),
    count: 4
}).between(new Date(2014, 8, 26), new Date(2014, 9, 1));

[
    "2014-09-25T22:30:00.000Z",
    "2014-09-26T22:30:00.000Z",
    "2014-09-26T22:30:00.000Z",
    "2014-09-28T21:30:00.000Z"
]

Tested (UTC+10:00) Canberra, Melbourne, Sydney IE9:

new RRule({
    freq: RRule.DAILY,
    dtstart: new Date(2014, 9, 3, 10, 30),
    count: 100
}).between(new Date(2014, 9, 3), new Date(2014, 11, 1));

0 : Fri Oct 3 10:30:00 UTC+1000 2014,
1 : Sat Oct 4 10:30:00 UTC+1000 2014,
2 : Sat Oct 4 10:30:00 UTC+1000 2014,
3 : Mon Oct 6 10:30:00 UTC+1100 2014,

image

Problem parsing rrule

looks like this rrule is not parsed correctly:
"FREQ=WEEKLY;INTERVAL=1;UNTIL=20130509;BYDAY=MO,TU,WE,TH,FR;WKST=SU"

byDay Interval

Hi first of all good job so far!
I've might found a problem with the byday rule and intervals.

If u test this rule:
FREQ=DAILY;BYDAY=MO;INTERVAL=3;UNTIL=20131101T000000Z;WKST=MO
It markes the first MO in february and than every third like expected.

If u test this rule where I just switched MO with TU:
FREQ=DAILY;BYDAY=TU;INTERVAL=3;UNTIL=20131101T000000Z;WKST=MO
It starts with the third TU of february. Schouldn't it start at the first TU too?

Thx

milliseconds truncated for returned occurrences

It appears that milliseconds are not carried forward in occurrences.
I know most occurrences don't matter at the level of milliseconds, but it could be useful in some cases, and it definitely allows me to write simpler tests.

The truncation of milliseconds causes my tests to fail:

expected:
"2014-06-08T16:51:13.976Z"
actual:
"2014-06-08T16:51:13.000Z"

rrule in bower repo doesn't work

I was using bower to checkout this project and it didn't work. When I download rrule.js manually from github then it works. There's indeed some differences between the codes. Perhaps bower version is not updated?

Disregard...

** Disregard...forgot about zero indexing...8-) **

var RRule = require('rrule').RRule;
var rule =  RRule.fromString('FREQ=DAILY;DTSTART=20131201T170000Z;WKST=MO;UNTIL=20131231T170000Z');
rule.between(new Date(2013,12,01), new Date(2013,12,31)); // []

rule.between() returns [] using Node 0.10.18 repl under OS X.

JSON (read javascript serialization) support

I want to use this on the client and server, but because of things like RRule.WEEKLY and RRule.WE = new Weekday(2) I can't just send it across.

What do you think about having some logic in the constructor to accept a pure JSON object and a proper .toJSON method?

// Create a rule:
var rule = new RRule({
    freq: 'weekly',
    interval: 5,
    byweekday: ['mo', 'fr'],
    dtstart: new Date(2012, 1, 1, 10, 30).toISOString(),
    until: new Date(2012, 12, 31).toISOString()
});

rule.toJSON();

Does not produce correct times for dates

Given:
DTSTART: 20070311T020000
RRULE: FREQ=YEARLY;BYMONTH=3;BYDAY=2SU

Produces:
Sun Mar 11 2007 18:00:00 GMT-0700 (PDT),
Sun Mar 09 2008 18:00:00 GMT-0700 (PDT),
Sun Mar 08 2009 18:00:00 GMT-0700 (PDT),
Sun Mar 14 2010 18:00:00 GMT-0700 (PDT),
...
Please Note:
Times are incorrect with respect to the DTSTART

Code to reproduce:

var rrule = require('rrule').RRule;
var options = rrule.parseString('FREQ=YEARLY;BYMONTH=3;BYDAY=2SU');

 if (options) {
    options.dtstart = new Date('2007-03-11T02:00:00');
    var RRule = new rrule(options);
    console.log(RRule.all());
    done();
}

Extra filtering

Hi
thank you this is good project

I want to add one feature

when freq is RRule.HOURLY or RRule.MINUTELY , RRule.SECONDLY

i need to work in specific time in day

ex: time from 3:00 to 6:00

i need add some Options parameter and filter result

Where do I put this code

thank you for help me

WKST and toString()

According to the RFC 2445 and 5545, shouldn't the WKST values be converted to the format "MO", "TU", "WE", etc. when calling toString()? Currently WKST values will be outputted as number values which some calendar applications deem invalid.

Usage of before and after?

var rfcString = 'FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=SU'
  , rule
  , d = new Date()
  , previous
  , current
  , current2
  , next
  ;

rule = RRule.fromString(rfcString);

previous = rule.before(d);
current = rule.after(d, true);
current2 = rule.after(d);

if (current.toString() === current2.toString()) {
  next = rule.after(current);
} else {
  next = current2;
}

console.log('Previous:', previous);
console.log('Current:', current);
console.log('Next:', next);

I get the following output:

Previous: null
Current: Sun Jan 26 2014 15:53:20 GMT-0700 (MST)
Next: Tue Jan 28 2014 15:53:20 GMT-0700 (MST)

I would expect this output instead:

Previous: Tue Jan 7 2014 15:53:20 GMT-0700 (MST)
Current: Sun Jan 19 2014 15:53:20 GMT-0700 (MST)
Next: Tue Jan 21 2014 15:53:20 GMT-0700 (MST)

Lodash Compat

So I'm just wondering you're going to plan on Lodash compatibility.

Right now rrule.js as is will not work 1:1 with Lodash without some manual patching (such as the chain method being gone) or using a compatibility build which has tons of missing features compared to a non compatibility build.

first event being created before wkst?

Unfortunately, I'm not an iCal/rrule expert, so this might be my interpretation being wrong, however, if I set the wkst value to be a day that is after today, I would assume that no events could take place today as part of this rule?

For instance, if today is friday, and i have a weekly rule that repeats on mon/tues/wed/thur/fri and I set the wkst to "SA", shouldn't the first event be monday of next week and NOT today (since friday is before saturday)?

I've attached a screenshot to help explain my question.

Thanks for an amazing script!

incorrect parsing byyearday, byweekno, byhour, byminute

It seems that double digit integers entered into some of the "by" fields get processed as two individual numbers instead of one value.

For instance, byhour of 10 gets interpreted as BYHOUR=1,0
Therefore, instead of something happening once at 10am, it occurs twice (right after midnight and 1am). Attempting to use "s to indicate a whole number doesn't seem to work. (Trying to separate additional values by ,'s generates NaN errors too)

rrule byhour question

Many tests fail...

Scratching my head for several hours now. It looks like a majority of the test cases fail for me, in fact, the only cases that pass are 1-8 and then a few throughout (very few) and 222-224. It almost looks like to me that RRule is setting the starting day at as a day earlier, as the expected results are behind 1:

testYearly:
Expected:
"Tue Sep 02 1997 09:00:00 GMT-0500 (Central Daylight Time)"
Result:
"Tue Sep 01 1998 09:00:00 GMT-0500 (Central Daylight Time)"

testYearlyByMonthDay:

Expected:
"Wed Sep 03 1997 09:00:00 GMT-0500 (Central Daylight Time)"
Result:
"Tue Sep 02 1997 09:00:00 GMT-0500 (Central Daylight Time)"
Diff:
"Wed "Tue Sep 03 02 1997 09:00:00 GMT-0500 (Central Daylight Time)"
Source:
at assertDatesEqual (file:///D:/Sites/rrule/test/utils.js:52:9)
at Object. (file:///D:/Sites/rrule/test/utils.js:85:9)

etc...

Are you getting the same?

Multidate event with "date_start" and "date_end" of each event occurence

Hi, I've recurring events like this:

FREQ=YEARLY;BYWEEKNO=45;BYDAY=SA,SU,MO;WKST=SA;DTSTART=20131101

Every year every weekno 45 from friday to next monday => MyEvent

1   Sat Nov 02  2013    01:00:00    GMT+0100    (CET)
2   Sun Nov 03  2013    01:00:00    GMT+0100    (CET)
3   Mon Nov 04  2013    01:00:00    GMT+0100    (CET)
4   Sat Nov 08  2014    01:00:00    GMT+0100    (CET)
5   Sun Nov 09  2014    01:00:00    GMT+0100    (CET)
6   Mon Nov 10  2014    01:00:00    GMT+0100    (CET)
7   Sat Nov 07  2015    01:00:00    GMT+0100    (CET)
8   Sun Nov 08  2015    01:00:00    GMT+0100    (CET)
9   Mon Nov 09  2015    01:00:00    GMT+0100    (CET)
10  Sat Nov 05  2016    01:00:00    GMT+0100    (CET)
...

Is possible or would you include in the api something like this:

rule.toEvents();
[
  [Sat  Nov 02  2013    01:00:00    GMT+0100    (CET), Mon  Nov 04  2013    01:00:00    GMT+0100    (CET)],
  [Sat  Nov 08  2014    01:00:00    GMT+0100    (CET), Mon  Nov 10  2014    01:00:00    GMT+0100    (CET)],
 /* [date_start,date_end] */]

I a few words the computation above grouped by adiacents events

nlp doesn't work :(

Hi,

Have you an example in an other langage because nlp use only english...

Thanks for your help.

dtstart seems to not be considered in some cases

I just updated to version 2.0.1.

In this example, I expect that after will contain the value of dtstart (which is one_hour_in), and that between will have dtstart as its first value.
However, it is missing in both cases.

This code is for node.js:

var rrule = require('rrule');
var RRule = rrule.RRule;
var start = new Date();
var end   = new Date(start.getTime() + 86400000); // One day after
var one_hour_in = new Date(start.getTime() + 3600000); // One hour after start
var rule = new RRule({
     freq: RRule.HOURLY,
     dtstart: one_hour_in,
     count: 1
 });
var after = rule.after(start);
var between = rule.between(start, end);

Example results:

> start
Fri Jun 06 2014 10:01:00 GMT-0700 (PDT)
> one_hour_in
Fri Jun 06 2014 11:01:00 GMT-0700 (PDT)
> end
Sat Jun 07 2014 10:01:00 GMT-0700 (PDT)

> after
Fri Jun 06 2014 12:01:00 GMT-0700 (PDT)
> between
[ Fri Jun 06 2014 12:01:00 GMT-0700 (PDT) ]

Documentation for i18n of toText

Please add better documentation about i18n of the toText() method.

  1. What's the meaning of the today parameter?
  2. Which values are passed to gettext?
  3. How do I actually translate stuff? I'm able to change dayNames and monthNames, but that's only part of it.

Thank you for creating this lib!

How to set tzid / timezone?

It appears that this uses the local time for calculations, but how do I calculate a schedule for another timezone?

Or perhaps I should call something like this?

date.toString().replace(/GMT.*/, 'GMT' + offset + ' (' + abbr + ')')

Use case:

i.e. I want to set a recurring event for 10am EST but the server that is actually running the code is PST, so despite the fact that the result set is converted to UTC, it's converted to the wrong UTC.

Mixed weekday rule bug

I'm not sure if it's just me, or it's actually a bug.

I'm trying to create a rule with mixed options for weekdays (byweekday). Refer to the following line of code:

WKST=SU;FREQ=MONTHLY;INTERVAL=1;BYDAY=MO,-1WE

In that example, I'm trying to create a recurring rule that must be every month on Mondays and on the last Wednesday.

First I thought it was a faulty logic in my code, however upon checking in the demo site (http://jakubroztocil.github.io/rrule/), I discovered that it actually doesn't output anything.

If I remove -1 from WE, meaning the rule would become every month on Mondays and Wednesdays, it works. If I put any nth for Monday, say 2MO, making the rule every month on the 2nd Monday and last Wednesday, it also works.

Is it a bug, or am I doing something wrong?
Thanks.

Time Zone Support

Is there a way to get a .between for an RRULE that is in a time zone other than the browser's current time zone? could the library make use of timezone-js to implement this functionality?

For example, if I'm in America/New_York but I have a recurrence that should be interpreted in Europe/Paris, the resulting dates should account for the daylight savings changes in the Europe/Paris time zone.

Edit: Digging deeper, would a change to

tzOffset: function(date) {
  return date.getTimezoneOffset() * 60 * 1000
}

fix this issue?

toText method has duplicate parameters.

The toText() method has duplicate parameters see:

Line: 879

    /**
    * Will convert all rules described in nlp:ToText
    * to text.
    */
    toText: function(today, today, gettext, language) {
        if (!_.has(this, '_text')) {
            this._text = getnlp().toText(this, today, gettext, language);
        }
        return this._text;
    },

It doesn't seem like you are calling this method anywhere..

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.