Skip to content

Instantly share code, notes, and snippets.

@AdrianTP
Created May 29, 2014 21:01
Show Gist options
  • Save AdrianTP/faf4eb3327986e231a21 to your computer and use it in GitHub Desktop.
Save AdrianTP/faf4eb3327986e231a21 to your computer and use it in GitHub Desktop.
Basic Event Generator
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));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment