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
|
2014-06-18 07:46:04 -04:00
|
|
|
end
|