From 0ec1f76d5e4937569cb92e1aedd6ff27bc5df0b4 Mon Sep 17 00:00:00 2001 From: Lars Henrik Mai Date: Tue, 18 Nov 2014 23:36:26 +0100 Subject: week calendar powered by OC json --- helpers/calendar_helpers.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'helpers/calendar_helpers.rb') diff --git a/helpers/calendar_helpers.rb b/helpers/calendar_helpers.rb index ed8ab16..3b915dc 100644 --- a/helpers/calendar_helpers.rb +++ b/helpers/calendar_helpers.rb @@ -37,5 +37,27 @@ module CalendarHelpers end + def week_schedule + events = data.calendar-week.map {|atts| Event.new(atts) } + events.group_by {|ev| ev.date } + end + + def events_on(datetime) + date = datetime.to_date + events = data.calendar.select do |hsh| + ev_date = DateTime.parse(hsh['start']).to_date + ev_date == date + end + events.map {|atts| Event.new(atts)} + end + + def current_week + monday = week_start(Date.parse("2014-11-18")) + (monday..monday + 6).to_a + end + + def week_start(date, offset_from_sunday=1) + date - (date.wday - offset_from_sunday) % 7 + end end -- cgit v1.2.1