forked from temmihoo/plushie-badname
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Event.js
46 lines (40 loc) · 1.27 KB
/
Event.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// This module creates events for calendar
module.exports.emitEvents = function(now, maxDelay){
'use strict';
var events = [];
var no_of_events = 0;
function generate_random_string(){
return Math.random().toString(36).slice(2);
}
function setStartTimeInSecondsFromNow(dflt){
var startAfter = null;
if (typeof maxDelay !== 'undefined'){
var startAfter = Math.floor(Math.random() * (maxDelay - 2) + 1);
}
else{
startAfter = dflt;
}
return startAfter;
}
no_of_events = Math.floor(Math.random() * 10 + 1);
for (var i = 0; i < no_of_events; i ++){
var startAfter = setStartTimeInSecondsFromNow(5);
var event = {
id: generate_random_string(),
begin: {
time: now.clone().add(startAfter.toString(), 'seconds'),
perform: function(){
console.log("Event starts");
}
},
end: {
time: now.clone().add((startAfter + 2).toString(), 'seconds'),
perform: function(){
console.log("Event ends");
}
}
};
events.push(event);
}
return events;
}