danielharan (owner)

Revisions

gist: 73599 Download_button fork
public
Public Clone URL: git://gist.github.com/73599.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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