Skip to content

Commit

Permalink
Add experimental TimeZone middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Dec 7, 2008
1 parent 01c3696 commit fc1964d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rack/contrib.rb
Expand Up @@ -14,4 +14,5 @@ def self.release
autoload :MailExceptions, "rack/mailexceptions" autoload :MailExceptions, "rack/mailexceptions"
autoload :PostBodyContentTypeParser, "rack/post_body_content_type_parser" autoload :PostBodyContentTypeParser, "rack/post_body_content_type_parser"
autoload :Sendfile, "rack/sendfile" autoload :Sendfile, "rack/sendfile"
autoload :TimeZone, "rack/time_zone"
end end
25 changes: 25 additions & 0 deletions lib/rack/time_zone.rb
@@ -0,0 +1,25 @@
module Rack
class TimeZone
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

def initialize(app)
@app = app
end

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
end
end

0 comments on commit fc1964d

Please sign in to comment.