From 48daaf51f94b7c2c23d31730d46b9fab151ab217 Mon Sep 17 00:00:00 2001 From: Lee Lawlor Date: Fri, 2 May 2014 12:58:00 -0400 Subject: [PATCH] parse time parameters in proper time zone --- app/controllers/application_controller.rb | 5 +++-- app/controllers/channels_controller.rb | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a13a854..96ada82 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -290,11 +290,12 @@ class ApplicationController < ActionController::Base # allow more past data if necessary get_old_data = (params[:results].present? || params[:start].present? || params[:days].present?) ? true : false + # set default start date start_date = (get_old_data) ? Time.parse('2010-01-01') : (Time.now - 1.day) end_date = Time.now start_date = (Time.now - params[:days].to_i.days) if params[:days] - start_date = DateTime.parse(params[:start]) if params[:start] - end_date = DateTime.parse(params[:end]) if params[:end] + start_date = ActiveSupport::TimeZone[Time.zone.name].parse(params[:start]) if params[:start] + end_date = ActiveSupport::TimeZone[Time.zone.name].parse(params[:end]) if params[:end] date_range = (start_date..end_date) # only get a maximum of 30 days worth of data date_range = (end_date - 30.days..end_date) if ((end_date - start_date) > 30.days and !get_old_data) diff --git a/app/controllers/channels_controller.rb b/app/controllers/channels_controller.rb index 83a6d7f..be69ca0 100644 --- a/app/controllers/channels_controller.rb +++ b/app/controllers/channels_controller.rb @@ -269,7 +269,7 @@ class ChannelsController < ApplicationController # try to get created_at datetime if appropriate if params[:created_at].present? begin - feed.created_at = DateTime.parse(params[:created_at]) + feed.created_at = ActiveSupport::TimeZone[Time.zone.name].parse(params[:created_at]) # if invalid datetime, don't do anything--rails will set created_at rescue end