Skip to content

Instantly share code, notes, and snippets.

@ejamesc
Last active December 23, 2015 05:49
Show Gist options
  • Select an option

  • Save ejamesc/6589096 to your computer and use it in GitHub Desktop.

Select an option

Save ejamesc/6589096 to your computer and use it in GitHub Desktop.
Setting timezones locally in Ruby
def with_time_zone(tz_name)
prev_tz = ENV['TZ']
ENV['TZ'] = tz_name
yield
ensure
ENV['TZ'] = prev_tz
end
with_time_zone('Asia/Singapore') { Chronic.parse("this week Monday 21:00") }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment