Skip to content

Instantly share code, notes, and snippets.

@kirel
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save kirel/9199495 to your computer and use it in GitHub Desktop.

Select an option

Save kirel/9199495 to your computer and use it in GitHub Desktop.

Revisions

  1. Daniel Kirsch revised this gist Feb 24, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions server.js
    Original 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');
    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 = 'My turn' || req.query.topic
    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);
    app.listen(process.env.PORT || 3000);
  2. Daniel Kirsch created this gist Feb 24, 2014.
    36 changes: 36 additions & 0 deletions server.js
    Original 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);