Socket
Book a DemoInstallSign in
Socket

timezone-aware

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timezone-aware

0.0.1
bundlerRubygems
Version published
Maintainers
1
Created
Source

TimezoneAware

Timezone aware uses JavaScript to detect a user's timezone. After the user's own timezone is detected (i.e. after the first request), Time.zone is set automatically in an around_filter for each request. In your views and controllers, you can simply call Time.zone.now and know this will be in the user's local time.

Installation

Add this line to your application's Gemfile:

gem 'timezone-aware'

Add timezone-aware.js to application.js

//=require timezone-aware

And then execute:

$ bundle

Or install it yourself as:

$ gem install timezone-aware

Usage

Timezone aware automatically sets Time.zone during each request. After the JavaScript determines the user's timezone (via jstz.js), we set a cookie time_zone. Timezone aware then sets Time.zone based on this cookie in an around_filter.

Note: this is not thread safe as global Time.zone is being set for each request.

Examples

An example view: home.html.erb

The time is now <%= Time.zone.now %>

Converting time zone back and forth

Time.now.utc.in_time_zone(Time.zone)

TODO

  • Add Poltergiest test cases
  • Explore ways to get correct timezone on first request
  • Explore ways to make thread safe

Contributing

  • Fork it ( https://github.com/hayesgm/timezone-aware/fork )
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create a new Pull Request

FAQs

Package last updated on 09 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.