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
| 230 | |
| 231 | |
| 232 | class 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 | |
| 256 | class TZWinContext(TZContextBase): |
no outgoing calls