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
| 110 | |
| 111 | |
| 112 | class 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 | |
| 136 | class TZWinContext(TZContextBase): |
no outgoing calls