Skip to content

Instantly share code, notes, and snippets.

@michaelminter
Created March 21, 2016 14:50
Show Gist options
  • Save michaelminter/b9176fe5790bf1f88d50 to your computer and use it in GitHub Desktop.
Save michaelminter/b9176fe5790bf1f88d50 to your computer and use it in GitHub Desktop.
Assigns time zone to local time zone. Then sets back.
# Assigns time zone to local time zone. Then sets back.
# @param [String] tz_name
# @example
# with_time_zone 'UTC' { something() }
def with_time_zone(tz_name)
prev_tz = ENV['TZ']
ENV['TZ'] = tz_name
yield
ensure
ENV['TZ'] = prev_tz
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment