GildedRose-Refactoring-Kata/venv/Lib/site-packages/approval_utilities/utilities/time_utilities.py

22 lines
524 B
Python

import os
from typing_extensions import ContextManager
def use_utc_timezone() -> ContextManager:
class TimeZoneSwap:
def __init__(self):
self.timezone = ""
def __enter__(self):
self.timezone = os.environ.get("TZ")
os.environ["TZ"] = "UCT"
def __exit__(self, exc_type, exc_val, exc_tb):
if self.timezone is None:
os.environ.pop("TZ")
else:
os.environ["TZ"] = self.timezone
return TimeZoneSwap()