Last active
August 29, 2015 13:56
-
-
Save kirel/9199495 to your computer and use it in GitHub Desktop.
Revisions
-
Daniel Kirsch revised this gist
Feb 24, 2014 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,15 +6,15 @@ var app = express(); moment.lang('de'); // make monday start of week app.get('/', function(req, res){ res.send('Subscribe to /:modulo/:residual?topic=topic i.e. <a href="http://modulocal.herokuapp.com/5/4?topic=Küchendienst">http://modulocal.herokuapp.com/5/4?topic=Küchendienst</a>.'); }); app.get('/:modulo/:residual', function(req, res){ var mod = parseInt(req.params.modulo); var rem = parseInt(req.params.residual); if(isNaN(mod)||isNaN(rem)) return res.send(400); res.set('Content-Type', 'text/calendar'); var topic = req.query.topic || 'My turn'; var cal = ical(); cal.setDomain('zweitag.de').setName(topic) var current = moment().week() % mod; @@ -33,4 +33,4 @@ app.get('/:modulo/:residual', function(req, res){ res.send(cal.toString().replace(/T000000/g,'')); }); app.listen(process.env.PORT || 3000); -
Daniel Kirsch created this gist
Feb 24, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ var express = require('express'); var moment = require('moment'); var ical = require('ical-generator'); var app = express(); moment.lang('de'); // make monday start of week app.get('/', function(req, res){ res.send('Subscribe to /:modulo/:residual'); }); app.get('/:modulo/:residual', function(req, res){ var mod = parseInt(req.params.modulo); var rem = parseInt(req.params.residual); if(isNaN(mod)||isNaN(rem)) return res.send(400); res.set('Content-Type', 'text/calendar'); var topic = 'My turn' || req.query.topic var cal = ical(); cal.setDomain('zweitag.de').setName(topic) var current = moment().week() % mod; var start = moment().startOf('year'); var end = moment().add('y', 1).startOf('year'); for (var i=1; moment().week(i+1).startOf('week') <= end ; i++) { if (i%mod!=rem) continue; var left = moment().week(i).startOf('week'); var right = moment().week(i+1).startOf('week'); if (left<start) left = start; if (right>end) right = end; cal.addEvent({ start: left.toDate(), end: right.toDate(), summary: topic }); } res.send(cal.toString().replace(/T000000/g,'')); }); app.listen(process.env.PORT || 3000);