2017-07-09 08:06:36 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:39:13 -04:00
|
|
|
|
2014-06-18 07:46:04 -04:00
|
|
|
module TimeZoneTestHelpers
|
|
|
|
def with_tz_default(tz = nil)
|
|
|
|
old_tz = Time.zone
|
|
|
|
Time.zone = tz
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
Time.zone = old_tz
|
|
|
|
end
|
|
|
|
|
2016-08-06 12:03:25 -04:00
|
|
|
def with_env_tz(new_tz = "US/Eastern")
|
|
|
|
old_tz, ENV["TZ"] = ENV["TZ"], new_tz
|
2014-06-18 07:46:04 -04:00
|
|
|
yield
|
|
|
|
ensure
|
2016-08-06 12:03:25 -04:00
|
|
|
old_tz ? ENV["TZ"] = old_tz : ENV.delete("TZ")
|
2014-06-18 07:46:04 -04:00
|
|
|
end
|
2016-04-23 09:46:50 -04:00
|
|
|
|
|
|
|
def with_preserve_timezone(value)
|
|
|
|
old_preserve_tz = ActiveSupport.to_time_preserves_timezone
|
|
|
|
ActiveSupport.to_time_preserves_timezone = value
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
ActiveSupport.to_time_preserves_timezone = old_preserve_tz
|
|
|
|
end
|
2018-04-17 16:03:02 -04:00
|
|
|
|
|
|
|
def with_tz_mappings(mappings)
|
|
|
|
old_mappings = ActiveSupport::TimeZone::MAPPING.dup
|
|
|
|
ActiveSupport::TimeZone.clear
|
|
|
|
ActiveSupport::TimeZone::MAPPING.clear
|
|
|
|
ActiveSupport::TimeZone::MAPPING.merge!(mappings)
|
|
|
|
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
ActiveSupport::TimeZone.clear
|
|
|
|
ActiveSupport::TimeZone::MAPPING.clear
|
|
|
|
ActiveSupport::TimeZone::MAPPING.merge!(old_mappings)
|
|
|
|
end
|
2014-06-18 07:46:04 -04:00
|
|
|
end
|