From 868882a0c992eca71ceb3f8e400beb23427f6512 Mon Sep 17 00:00:00 2001 From: Lee Lawlor Date: Tue, 5 Aug 2014 12:20:10 -0400 Subject: [PATCH] allow timezone parameters to work correctly with charts --- app/controllers/application_controller.rb | 3 +++ app/helpers/feed_helper.rb | 8 +++++++- app/models/daily_feed.rb | 6 ++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9fb474e..85964fb 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -328,6 +328,9 @@ class ApplicationController < ActionController::Base # use the offset to find an appropriate timezone def set_timezone_from_offset(offset) offset = offset.to_i + # always set to UTC if offset is 0 + return 'UTC' if offset == 0 + # keep track of the currently matched time zone current_zone = nil diff --git a/app/helpers/feed_helper.rb b/app/helpers/feed_helper.rb index 7338ea3..bc7c5c6 100644 --- a/app/helpers/feed_helper.rb +++ b/app/helpers/feed_helper.rb @@ -99,9 +99,15 @@ module FeedHelper empty_clone.attribute_names.each { |attr| empty_clone[attr] = nil } return empty_clone end + + # get the time floored to the correct number of seconds def get_floored_time(input_time, seconds) - return Time.zone.at((input_time.to_f / seconds).floor * seconds) + floored_seconds = (input_time.to_f / seconds).floor * seconds + # offset the seconds by the current time zone offset + offset_seconds = Time.zone.now.utc_offset + return Time.at(floored_seconds - offset_seconds) end + # slice feed into timescales def feeds_into_timescales(feeds, params) diff --git a/app/models/daily_feed.rb b/app/models/daily_feed.rb index 47a68bd..17a4a1b 100644 --- a/app/models/daily_feed.rb +++ b/app/models/daily_feed.rb @@ -39,9 +39,11 @@ class DailyFeed < ActiveRecord::Base return output end - # checks to see if this is a daily feed + # checks to see if this is a daily feed, only works for timezone UTC (offset == 0) def self.valid_params(params) - (params[:timescale] == '1440' || params[:sum] == '1440' || params[:average] == '1440' || params[:median] == '1440') ? true : false + daily_params = (params[:timescale] == '1440' || params[:sum] == '1440' || params[:average] == '1440' || params[:median] == '1440') ? true : false + return daily_params && (Time.zone.name == 'UTC') end end +