@contextmanager
def set_timezone(tz):
 if is_platform_windows():
  import nose
  raise nose.SkipTest('timezone setting not supported on windows')
 import os
 import time
 def setTZ(tz):
  if (tz is None):
   try:
    del os.environ['TZ']
   except:
    pass
  else:
   os.environ['TZ'] = tz
   time.tzset()
 orig_tz = os.environ.get('TZ')
 setTZ(tz)
 try:
  (yield)
 finally:
  setTZ(orig_tz)

@ contextmanager def set_timezone ( tz ) : if is_platform_windows ( ) : import nose raise nose . SkipTest ( 'timezone setting not supported on windows' ) import os import time def setTZ ( tz ) : if ( tz is None ) : try : del os . environ [ 'TZ' ] except : pass else : os . environ [ 'TZ' ] = tz time . tzset ( ) orig_tz = os . environ . get ( 'TZ' ) setTZ ( tz ) try : ( yield ) finally : setTZ ( orig_tz )
context manager for temporarily setting a timezone .