38 lines
575 B
Python
38 lines
575 B
Python
try:
|
|
# noinspection PyUnresolvedReferences
|
|
import pytz
|
|
|
|
def tz(tz_str):
|
|
return pytz.timezone(tz_str)
|
|
except ImportError:
|
|
import zoneinfo
|
|
|
|
def tz(tz_str):
|
|
return zoneinfo.ZoneInfo(tz_str)
|
|
|
|
from datetime import datetime, timezone
|
|
|
|
|
|
class Current:
|
|
value = timezone.utc
|
|
|
|
|
|
_current = Current()
|
|
|
|
|
|
def set_current(tz_str):
|
|
_current.value = tz(tz_str)
|
|
pass
|
|
|
|
|
|
def get_current():
|
|
return _current.value
|
|
|
|
|
|
def now():
|
|
return _current.value.localize(datetime.now())
|
|
|
|
|
|
def make_aware(value):
|
|
return _current.value.localize(value)
|