-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent.coffee
More file actions
38 lines (29 loc) · 981 Bytes
/
event.coffee
File metadata and controls
38 lines (29 loc) · 981 Bytes
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
moment = require 'moment'
parser = require 'xml2json'
rest = require 'restler'
ical = require 'ical'
require 'datejs'
parseFeed = (feed) ->
JSON.parse(parser.toJson(feed)).feed.entry
formatDate = (start, end) ->
start = moment(start.setTimezone("CST"))
end = moment(end.setTimezone("CST"))
date = start.format('ddd, MMM D')
if end.diff(start, 'days') == 1 and start.hours() == 0
return date
date + start.format(' h:mma CST')
eventFeed = 'http://www.google.com/calendar/ical/nodekc.org_e8lg6hesldeld1utui23ebpg7k%40group.calendar.google.com/public/basic.ics'
Event = (data) ->
this.title = data.summary
this.location = data.location
this.details = data.description
this.when = formatDate(data.start, data.end)
this.url = 'http://calendar.nodekc.org'
return
Event.load = (cb) ->
ical.fromURL eventFeed, {}, (err, calendar) ->
calendar or= {}
events = for k,v of calendar
new Event v
cb events
module.exports = Event