Comments (5)
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.
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.
Would you include a method like that in your source?
from rrule.
@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.
No, prob., I already organized it as a separate module. I asked just because it is a single method
from rrule.
Related Issues (20)
- the `until` parser throws an error on hermes
- `between` is 10X slower than before when there is a TZID in the rrule. HOT 4
- Make return type of `rrulestr` depend on `forceset` option
- RRuleSet toString() get a string result, but parse this string result can not restore previous RRuleSet, the time is not right
- [Bug] Over until date
- Dates on month and day of DTSTART that are after UNTIL date are included in output HOT 1
- datetime in RRule Cant be used : possible fix
- RRule Issue on Weekly when time specified 12AM - 8AM
- Parsing bug in rrulestr function HOT 1
- Many warnings in logs when installing the library
- NLP: Support weekly by hour patterns
- Fractions crash the app
- Feature: exception rule HOT 2
- rrule.min.js is offline HOT 1
- UNTIL is miscalculated when DTSTART has timezone (TZID)
- Missing dates for weekly with count HOT 1
- byweekday undefined has different behavior than empty array
- Broken the link HOT 2
- Combining MINUTELY with BYHOUR and BYDAY misses out days when used with just one BYHOUR value
- Possible solution for "Invalid UNTIL value"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rrule.