forked from rack/rack-contrib
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental TimeZone middleware
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |