Skip to content

Commit

Permalink
Added support for rrule handling in ics events
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirk Melchers committed Oct 26, 2014
1 parent dd5bf51 commit 8e4ebde
Show file tree
Hide file tree
Showing 3 changed files with 1,940 additions and 2 deletions.
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<script src="js/ical_parser.js"></script>
<script src="js/moment-with-langs.min.js"></script>
<script src="js/config.js"></script>
<script src="js/rrule.js"></script>
<script src="js/main.js?nocache=<?php echo md5(microtime()) ?>"></script>
<script src="js/socket.io.min.js"></script>

Expand Down
31 changes: 29 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,36 @@ jQuery(document).ready(function($) {
}else {
var time_string = moment(startDate).calendar()
}
eventList.push({'description':e.SUMMARY,'seconds':seconds,'days':time_string});
if (!e.RRULE) {
eventList.push({'description':e.SUMMARY,'seconds':seconds,'days':time_string});
}
e.seconds = seconds;
}
};

// Special handling for rrule events
if (e.RRULE) {
var options = new RRule.parseString(e.RRULE);
options.dtstart = e.startDate;
var rule = new RRule(options);

// TODO: don't use fixed end date here, use something like now() + 1 year
var dates = rule.between(new Date(), new Date(2016,11,31), true, function (date, i){return i < 10});
for (date in dates) {
var dt = new Date(dates[date]);
var days = moment(dt).diff(moment(), 'days');
var seconds = moment(dt).diff(moment(), 'seconds');
var startDate = moment(dt);
if (seconds >= 0) {
if (seconds <= 60*60*5 || seconds >= 60*60*24*2) {
var time_string = moment(dt).fromNow();
} else {
var time_string = moment(dt).calendar()
}
eventList.push({'description':e.SUMMARY,'seconds':seconds,'days':time_string});
}
}
}
};
eventList.sort(function(a,b){return a.seconds-b.seconds});

setTimeout(function() {
Expand Down
Loading

0 comments on commit 8e4ebde

Please sign in to comment.