
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
rails_browser_timezone
Advanced tools
The purpose of this gem is to track browser's timezone and run rails controller code in the time zone detected for each request.
For background and thoughts, please refer - http://developerstream.blogspot.in/2015/09/handling-requests-in-browser-time-zone.html
gem 'rails_browser_timezone', '0.2.0', :git => 'https://github.com/udayakiran/rails_browser_timezone'
# Say in config/initializers/rails_browser_tz_init.rb
RailsBrowserTimezone::Setting.baseline_year = 2014 #default value is 2011. Accepted values - any valid year or string - "current"
#Rails 4.1.x or earlier (inlcuding Rails 2,3 and 4)
class MyTimeZoneController < ApplicationController #Or in your application_controller.rb
prepend_around_filter RailsBrowserTimezone::Filter
.......
.......
end
#Rails 4.2.x or later
class MyTimeZoneController < ApplicationController #Or in your application_controller.rb
prepend_around_action RailsBrowserTimezone::Filter
.......
.......
end
If you like to save the last_known_timezone of any user in the database, it can be done by using "Time.zone.name" any where in your controller, once 'RailsBrowserTimezone::Filter' is done with the determining of the time zone from offsets.
Use Time.zone.* not Time.* :- Most of the scenarios we need to deal with times in the current time zone not in the system time zone on which app is running. So, we should use Time.zone.now, Time.zone.parse and time_obj.in_time_zone(Time.zone) when we are dealing with time information.
Use Time.use_zone :- When we need to operate in other time zones than the current system, enlose that code in Time.use_zone block. This sets back the system time zone once the code completes execution or even when exception occurs. Otherwise we should always remember to set the system's time zone back to default.
Add specs and tests.
Please help with your contribution by filing any issues if found. Pull requests are welcomed :)
FAQs
Unknown package
We found that rails_browser_timezone demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.