MCPcopy Create free account
hub / github.com/dateutil/dateutil / TZEnvContext

Class TZEnvContext

tests/_common.py:232–253  ·  view source on GitHub ↗

Context manager that temporarily sets the `TZ` variable (for use on *nix-like systems). Because the effect is local to the shell anyway, this will apply *unless* a guard is set. If you do not want the TZ environment variable set, you may set the ``DATEUTIL_MAY_NOT_CHANGE_TZ_VAR

Source from the content-addressed store, hash-verified

230
231
232class TZEnvContext(TZContextBase):
233 """
234 Context manager that temporarily sets the `TZ` variable (for use on
235 *nix-like systems). Because the effect is local to the shell anyway, this
236 will apply *unless* a guard is set.
237
238 If you do not want the TZ environment variable set, you may set the
239 ``DATEUTIL_MAY_NOT_CHANGE_TZ_VAR`` variable to a truthy value.
240 """
241 _guard_var_name = "DATEUTIL_MAY_NOT_CHANGE_TZ_VAR"
242 _guard_allows_change = False
243
244 def get_current_tz(self):
245 return os.environ.get('TZ', UnsetTz)
246
247 def set_current_tz(self, tzval):
248 if tzval is UnsetTz and 'TZ' in os.environ:
249 del os.environ['TZ']
250 else:
251 os.environ['TZ'] = tzval
252
253 time.tzset()
254
255
256class TZWinContext(TZContextBase):

Callers 15

test_tzlocal_in_gmtMethod · 0.85
_gettz_contextMethod · 0.85
_testTzFuncMethod · 0.85
testUTCEqualityMethod · 0.85
test_tzlocal_utc_equalFunction · 0.85
test_tzlocal_utc_unequalFunction · 0.85

Calls

no outgoing calls

Tested by 15

test_tzlocal_in_gmtMethod · 0.68
_gettz_contextMethod · 0.68
_testTzFuncMethod · 0.68
testUTCEqualityMethod · 0.68
test_tzlocal_utc_equalFunction · 0.68
test_tzlocal_utc_unequalFunction · 0.68