Skip to content

Commit

Permalink
Memoize timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
henadzit committed Jan 5, 2025
1 parent fe8ea66 commit 96923e1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tortoise/timezone.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from functools import cache
import os
from datetime import datetime, time, tzinfo
from typing import Optional, Union

import pytz


@cache
def get_use_tz() -> bool:
"""
Get use_tz from env set in Tortoise config.
"""
return os.environ.get("USE_TZ") == "True"


@cache
def get_timezone() -> str:
"""
Get timezone from env set in Tortoise config.
Expand All @@ -29,6 +32,7 @@ def now() -> datetime:
return datetime.now(get_default_timezone())


@cache
def get_default_timezone() -> tzinfo:
"""
Return the default time zone as a tzinfo instance.
Expand Down

0 comments on commit 96923e1

Please sign in to comment.