Skip to content

Instantly share code, notes, and snippets.

@AdrianTP
Created May 29, 2014 21:01
Show Gist options
  • Select an option

  • Save AdrianTP/faf4eb3327986e231a21 to your computer and use it in GitHub Desktop.

Select an option

Save AdrianTP/faf4eb3327986e231a21 to your computer and use it in GitHub Desktop.

Revisions

  1. Adrian Thomas-Prestemon created this gist May 29, 2014.
    26 changes: 26 additions & 0 deletions basicEventGenerator
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    var event = function(id, year, month) {
    var zeroMonth = (function(month) {
    var mo = "" + month;
    return (mo.length < 2) ? "0" + mo : mo;
    })(month),
    randomDate = (function(from, to) {
    var num = "" + Math.floor(Math.random() * (to - from + 1) + from);
    return (num.length < 2) ? "0" + num : num;
    })(1, 28),
    dateString = "" + year + "-" + zeroMonth + "-" + randomDate + "T00:00:00Z";
    return {
    "id": id,
    "date": +new Date(dateString),
    "name": "Event " + id
    };
    };

    var generateDates = function(year, month, num) {
    out = [];
    for (var i = 1; i <= num; ++ i) {
    out.push(new event(i, year, month));
    }
    return JSON.stringify(out, null, 4);
    };

    console.log(generateDates(2014,5,10));