Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
B

browser-timezone-rails

> 编程语言
Open source

Rails engine that sets the Rails timezone to the browser time zone for each request.

182 stars0 likes1 views
WebsiteGitHub

About

Rails engine that sets the Rails timezone to the browser time zone for each request.

BrowserTimezoneRails

Rails Engine which sets the Rails timezone to the browser's configured timezone for each request.

Installation

Add it to your Gemfile.

ruby
gem 'browser-timezone-rails'

Make sure you have each of the following entries in your application.js:

//= require js.cookie
//= require browser_timezone_rails/set_time_zone

That's it! No other configuration is needed as it's all done for you with this gem including setting up your application controller to start using your users' zones.

How it works

The browser's timezone is set in a cookie using the modern ECMAScript Internationalization API

Caveat: doesn't work with Internet Explorer.

(Up to 1.0.4 version of the gem, the cookie was set via the jsTimezoneDetect javascript library, which, however, was often inaccurate.)

That cookie is then read during each request to set the Rails timezone for that user.

You can also read more about this implementation here: Blog

For those of you who need or want to do this on the backend with just Rails, Ryan Bates has a good RailsCast on how to that: RailsCast #106

About that cookie

The cookie is set each full page request and lives for 365 days

Thread safety

Yes. It uses the Rails Time.zone method which is thread safe.

Caveat

The first request ever made by a user's browser to your app will not set the browser's time zone as the javascript that sets the cookie has not yet run on their browser. This will only happen once and for me it was not a problem.

Development

To run the tests, invoke bundle exec rspec.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言