MCPcopy
hub / github.com/tortoise/tortoise-orm / parse_timezone

Function parse_timezone

tortoise/timezone.py:26–40  ·  view source on GitHub ↗
(zone: str)

Source from the content-addressed store, hash-verified

24
25
26def parse_timezone(zone: str) -> tzinfo:
27 if zone.upper() == "UTC":
28 return ZoneInfo("UTC")
29 try:
30 return ZoneInfo(zone)
31 except ZoneInfoNotFoundError as e:
32 words = zone.split("/")
33 # Compatible with `pytz.timezone`:
34 # US/central -> US/Central
35 # Europe/moscow -> Europe/Moscow
36 # asia/ShangHai -> Asia/Shanghai
37 styled = "/".join([i if i.isupper() else i.title() for i in words])
38 if styled != zone:
39 return ZoneInfo(styled)
40 raise e
41
42
43@functools.cache

Callers 5

test_datetime_timezoneFunction · 0.90
test_zoneinfoFunction · 0.90
get_default_timezoneFunction · 0.85
_get_or_parse_timezoneFunction · 0.85

Calls 1

ZoneInfoClass · 0.85

Tested by 3

test_datetime_timezoneFunction · 0.72
test_zoneinfoFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…