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

Class TZEnvContext

tests/_common.py:112–133  ·  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

110
111
112class TZEnvContext(TZContextBase):
113 """
114 Context manager that temporarily sets the `TZ` variable (for use on
115 *nix-like systems). Because the effect is local to the shell anyway, this
116 will apply *unless* a guard is set.
117
118 If you do not want the TZ environment variable set, you may set the
119 ``DATEUTIL_MAY_NOT_CHANGE_TZ_VAR`` variable to a truthy value.
120 """
121 _guard_var_name = "DATEUTIL_MAY_NOT_CHANGE_TZ_VAR"
122 _guard_allows_change = False
123
124 def get_current_tz(self):
125 return os.environ.get('TZ', UnsetTz)
126
127 def set_current_tz(self, tzval):
128 if tzval is UnsetTz and 'TZ' in os.environ:
129 del os.environ['TZ']
130 else:
131 os.environ['TZ'] = tzval
132
133 time.tzset()
134
135
136class 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