Git Product home page Git Product logo

Comments (5)

jkbrzt avatar jkbrzt commented on May 26, 2024

This is not directly supported but you can still do that manually. For example:

var rule = 'FREQ=YEARLY;BYWEEKNO=45;BYDAY=SA;DTSTART=20131101;COUNT=3';
var events = [];

RRule.fromString(rule).all(function(start){ 
    var end = new Date(start.getTime()); 
    end.setDate(start.getDate() + 2); 
    events.push([start, end]); 
    return true;
})

console.table(events);

0
Sat Nov 09 2013 01:00:00 GMT+0100 (CET)
Mon Nov 11 2013 01:00:00 GMT+0100 (CET)
1
Sat Nov 08 2014 01:00:00 GMT+0100 (CET)
Mon Nov 10 2014 01:00:00 GMT+0100 (CET)
2
Sat Nov 07 2015 01:00:00 GMT+0100 (CET)
Mon Nov 09 2015 01:00:00 GMT+0100 (CET)

from rrule.

grigio avatar grigio commented on May 26, 2024

Thanks, unfortunatly I can't assume the date_end from the date_start but I know there is a date_end only if the next date has more than a day gap from the current one.

Currently It works and I implemented a "toEvents()" method like this:

  REvent.prototype.toEvents = function() {

    function isConsecutive (start, end) {
      var tomorrow = new Date(start.getTime() + (24 * 60 * 60 * 1000) +1);
      return end <= tomorrow;
    }

    var dates  = _obj; // Array of sequential dates
    var events = [];   // Array of pairs date_start, date_end

    var ds = 0;
    while (ds < dates.length){
      var date_start = dates[ds];
      var de = ds;
      while (de < dates.length){
        if ( isConsecutive(dates[de], dates[de+1]) ) { 
          // continue
        } else {
          events.push({date_start: date_start, date_end: dates[de]});
          ds = de;
          de = dates.length; // force quit
        }
        de++;
      }
      ds++;
    }

    return events;
  }

Do you know a smarter way?

from rrule.

grigio avatar grigio commented on May 26, 2024

Would you include a method like that in your source?

from rrule.

jkbrzt avatar jkbrzt commented on May 26, 2024

@grigio I think it's a bit too specific for inclusion into RRule. But maybe you could generalize it a bit and release it as a standalone library.

from rrule.

grigio avatar grigio commented on May 26, 2024

No, prob., I already organized it as a separate module. I asked just because it is a single method

from rrule.

Related Issues (20)

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.