mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-04-03 09:45:14 +08:00
22 lines
329 B
Ruby
22 lines
329 B
Ruby
def with_timezone(name, offset = nil, daylight_saving_zone = "")
|
|
zone = name.dup
|
|
|
|
if offset
|
|
# TZ convention is backwards
|
|
offset = -offset
|
|
|
|
zone << offset.to_s
|
|
zone << ":00:00"
|
|
end
|
|
zone << daylight_saving_zone
|
|
|
|
old = ENV["TZ"]
|
|
ENV["TZ"] = zone
|
|
|
|
begin
|
|
yield
|
|
ensure
|
|
ENV["TZ"] = old
|
|
end
|
|
end
|