Skip to content
Browse files

Add experimental TimeZone middleware

  • Loading branch information...
1 parent 01c3696 commit fc1964d47cfb15c6a1b37db7b4c9ce0a27ae2ccb @josh josh committed Dec 7, 2008
Showing with 26 additions and 0 deletions.
  1. +1 −0 lib/rack/contrib.rb
  2. +25 −0 lib/rack/time_zone.rb
View
1 lib/rack/contrib.rb
@@ -14,4 +14,5 @@ def self.release
autoload :MailExceptions, "rack/mailexceptions"
autoload :PostBodyContentTypeParser, "rack/post_body_content_type_parser"
autoload :Sendfile, "rack/sendfile"
+ autoload :TimeZone, "rack/time_zone"
end
View
25 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.
Something went wrong with that request. Please try again.