Don't lazy load the tzinfo library
Lazy loading the tzinfo library doesn't really buy us anything because the gem is installed as a dependency via the gemspec and if a developer is using Active Support outside of Rails then they can cherry pick which files to load anyway. Fixes #13553
This commit is contained in:
parent
e97d48f17e
commit
75ad0e642c
@ -1,3 +1,9 @@
|
|||||||
|
* Don't lazy load the `tzinfo` library as it causes problems on Windows.
|
||||||
|
|
||||||
|
Fixes #13553
|
||||||
|
|
||||||
|
*Andrew White*
|
||||||
|
|
||||||
* Use `remove_possible_method` instead of `remove_method` to avoid
|
* Use `remove_possible_method` instead of `remove_method` to avoid
|
||||||
a `NameError` to be thrown on FreeBSD with the `Date` object.
|
a `NameError` to be thrown on FreeBSD with the `Date` object.
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
require 'tzinfo'
|
||||||
require 'thread_safe'
|
require 'thread_safe'
|
||||||
require 'active_support/core_ext/object/blank'
|
require 'active_support/core_ext/object/blank'
|
||||||
require 'active_support/core_ext/object/try'
|
require 'active_support/core_ext/object/try'
|
||||||
@ -208,8 +209,6 @@ def self.seconds_to_utc_offset(seconds, colon = true)
|
|||||||
# (GMT). Seconds were chosen as the offset unit because that is the unit
|
# (GMT). Seconds were chosen as the offset unit because that is the unit
|
||||||
# that Ruby uses to represent time zone offsets (see Time#utc_offset).
|
# that Ruby uses to represent time zone offsets (see Time#utc_offset).
|
||||||
def initialize(name, utc_offset = nil, tzinfo = nil)
|
def initialize(name, utc_offset = nil, tzinfo = nil)
|
||||||
self.class.send(:require_tzinfo)
|
|
||||||
|
|
||||||
@name = name
|
@name = name
|
||||||
@utc_offset = utc_offset
|
@utc_offset = utc_offset
|
||||||
@tzinfo = tzinfo || TimeZone.find_tzinfo(name)
|
@tzinfo = tzinfo || TimeZone.find_tzinfo(name)
|
||||||
@ -389,7 +388,7 @@ def [](arg)
|
|||||||
case arg
|
case arg
|
||||||
when String
|
when String
|
||||||
begin
|
begin
|
||||||
lazy_zones_map[arg] ||= create(arg).tap { |tz| tz.utc_offset }
|
@lazy_zones_map[arg] ||= create(arg).tap { |tz| tz.utc_offset }
|
||||||
rescue TZInfo::InvalidTimezoneIdentifier
|
rescue TZInfo::InvalidTimezoneIdentifier
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
@ -406,22 +405,6 @@ def [](arg)
|
|||||||
def us_zones
|
def us_zones
|
||||||
@us_zones ||= all.find_all { |z| z.name =~ /US|Arizona|Indiana|Hawaii|Alaska/ }
|
@us_zones ||= all.find_all { |z| z.name =~ /US|Arizona|Indiana|Hawaii|Alaska/ }
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def require_tzinfo
|
|
||||||
require 'tzinfo' unless defined?(::TZInfo)
|
|
||||||
rescue LoadError
|
|
||||||
$stderr.puts "You don't have tzinfo installed in your application. Please add it to your Gemfile and run bundle install"
|
|
||||||
raise
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def lazy_zones_map
|
|
||||||
require_tzinfo
|
|
||||||
@lazy_zones_map
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
Loading…
Reference in New Issue
Block a user