From 3194764c46aa539c75f7590323bb355709135b0d Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 17 Dec 2014 18:25:53 +0800 Subject: [PATCH] fix for time zones --- app/assets/javascripts/calendar_frontend.js | 6 ++++-- app/controllers/admin/calendars_controller.rb | 4 ++-- app/controllers/calendars_controller.rb | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/calendar_frontend.js b/app/assets/javascripts/calendar_frontend.js index 0b0767e..a5980b8 100644 --- a/app/assets/javascripts/calendar_frontend.js +++ b/app/assets/javascripts/calendar_frontend.js @@ -285,11 +285,13 @@ var AgendaView = function(calendar){ var eventsManager = function(){ var url = "/xhr/calendars/agenda", sd = new Date(start_year,start_month,1), - ed = new Date(end_year,end_month+1,0); + ed = new Date(end_year,end_month+1,0), + usd = Math.round(sd/1000), + ued = Math.round(ed/1000); $.ajax({ type : "get", url : url, - data : {"agenda_start":sd.toLocaleString(),"agenda_end":ed.toLocaleString(),"page_id" : _calendar.page_id}, + data : {"agenda_start":sd.toLocaleString(),"agenda_end":ed.toLocaleString(),"page_id" : _calendar.page_id,"unix_start":usd,"unix_end":ued}, success : function(events){ $.each(events,function(i,e){ var ed = eventDom(e), diff --git a/app/controllers/admin/calendars_controller.rb b/app/controllers/admin/calendars_controller.rb index 83514e9..25b115f 100644 --- a/app/controllers/admin/calendars_controller.rb +++ b/app/controllers/admin/calendars_controller.rb @@ -34,8 +34,8 @@ class Admin::CalendarsController < OrbitAdminController end def agenda - agenda_start = Date.strptime(params[:agenda_start], '%m/%d/%Y') - agenda_end = Date.strptime(params[:agenda_end], '%m/%d/%Y') + agenda_start = Time.at(params[:unix_start].to_i).to_s + agenda_end = Time.at(params[:unix_end].to_i).to_s @events = Event.agenda_events(agenda_start,agenda_end) # re = Event.recurring_event(Time.at(params[:unix_start].to_i), Time.at(params[:unix_end].to_i)) # @events = @events.inject(re, :<<) diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index e0d412e..e59ce6f 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -45,9 +45,9 @@ class CalendarsController < ApplicationController else calendar_types = CalendarType.where(:category_id.in => categories).collect{|ct| ct.id.to_s } rescue [] end - if params[:agenda_start].present? && params[:agenda_end].present? - agenda_start = Date.strptime(params[:agenda_start], '%m/%d/%Y') - agenda_end = Date.strptime(params[:agenda_end], '%m/%d/%Y') + if params[:unix_start].present? && params[:unix_end].present? + agenda_start = Time.at(params[:unix_start].to_i).to_s + agenda_end = Time.at(params[:unix_end].to_i).to_s events = Event.agenda_events(agenda_start,agenda_end).where(:calendar_type_id.in => calendar_types) end end