Created
March 3, 2009 22:57
-
-
Save danielharan/73599 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
def set_time_zone | |
if current_user | |
Time.zone = current_user.time_zone | |
logger.debug "set time zone to #{Time.zone.name}" | |
end | |
end | |
end | |
class Reports::BaseController < ApplicationController | |
protected | |
def normalize_date_range | |
logger.debug "normalizing date range" | |
@start_period = normalized_start_period | |
@end_period = normalized_end_period | |
@start_period, @end_period = @end_period, @start_period if @start_period > @end_period | |
logger.debug "start: #{@start_period}" | |
end | |
def normalized_start_period | |
params_or_default(:start_period).at_beginning_of_day | |
end | |
def normalized_end_period | |
params_or_default(:end_period).end_of_day | |
end | |
def params_or_default(key) | |
if params[key].blank? | |
Time.zone.now - 1.day | |
else | |
Time.zone.parse(params[key]) | |
end | |
end | |
end | |
# on local machine, having set time zone to EST | |
set time zone to Eastern Time (US & Canada) | |
normalizing date range | |
start: 2009-03-02 00:00:00 -0500 | |
$ ruby -v | |
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0] | |
$ rails -v | |
Rails 2.2.2 | |
# on server, setting it to +13 | |
set time zone to Nuku'alofa | |
normalizing date range | |
start: Mon Mar 02 00:00:00 -0500 2009 # it's *always* this, no matter what the time we set for user | |
$ ruby -v | |
ruby 1.8.6 (2008-03-03 patchlevel 114) [x86_64-linux] | |
$ rails -v | |
Rails 2.2.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment