-
Notifications
You must be signed in to change notification settings - Fork 0
/
formEvent.js
58 lines (56 loc) · 1.58 KB
/
formEvent.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
47
48
49
50
51
52
53
54
55
56
57
58
var chrono = require('chrono-node');
var parse = require('parse-messy-schedule');
function formEvent(info) {
return new Promise(function(resolve, reject) {
console.log(info);
const dates = info.time.map(time=>chrono.parseDate(time));
const dateStart = dates.reduce((actual,next)=>{
if (!next) return actual
return (actual>next)?actual:next
})
const dateEnd = dates.reduce((actual,next)=>{
if (!next) return actual
return (actual<next)?actual:next
})
const attendees = info.email.map(email=>({'email':email}));
attendees.concat(info.people.map(person=>({'displayName':person})));
// const recurrence = parse(info.time.join(', '));
// if (recurrence._every.every) {
//
// }
// console.log("RECURRENCE",recurrence,"\n\n\n\n\n");
var event = {
'summary': info.raw.split(' ').slice(0,5).join(' '),
'location': info.place.join(', '),
'start': {
'dateTime': dateStart,
'timeZone': 'America/Los_Angeles'
},
'end': {
'dateTime': dateEnd,
'timeZone': 'America/Los_Angeles'
},
// 'recurrence': ['RRULE:FREQ=DAILY;COUNT=2'],
'attendees': attendees,
'description': info.raw,
'attachments': [],
'reminders': {
'useDefault': false,
'overrides': [
{
'method': 'email',
'minutes': 24 * 60
}, {
'method': 'popup',
'minutes': 10
}
]
}
};
// if (err) {
// reject(err)
// }
resolve(event)
});
}
module.exports = formEvent