Class: Rack::TimeZone

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/contrib/time_zone.rb

Constant Summary collapse

Javascript =
<<-EOJ
    function setTimezoneCookie() {
      var offset = (new Date()).getTimezoneOffset()
      var date = new Date();
      date.setTime(date.getTime()+3600000);
      document.cookie = "utc_offset="+offset+"; expires="+date.toGMTString();+"; path=/";
    }
EOJ

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ TimeZone

Returns a new instance of TimeZone.



12
13
14
# File 'lib/rack/contrib/time_zone.rb', line 12

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/rack/contrib/time_zone.rb', line 16

def call(env)
  request = Rack::Request.new(env)
  if utc_offset = request.cookies["utc_offset"]
    env["rack.timezone.utc_offset"] = -(utc_offset.to_i * 60)
  end

  @app.call(env)
end