mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
switch to zoneinfo from pytz
This commit is contained in:
parent
e5814ea486
commit
d2d4a44705
@ -21,11 +21,11 @@ from django.core.files.storage import Storage, default_storage
|
||||
from django.http import StreamingHttpResponse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
import pytz
|
||||
import regex
|
||||
from bleach import clean
|
||||
from djmoney.money import Money
|
||||
from PIL import Image
|
||||
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
||||
|
||||
import InvenTree.version
|
||||
from common.currency import currency_code_default
|
||||
@ -926,15 +926,15 @@ def to_local_time(time, target_tz: str = None):
|
||||
|
||||
if not source_tz:
|
||||
# Default to UTC if not provided
|
||||
source_tz = pytz.utc
|
||||
source_tz = ZoneInfo('UTC')
|
||||
|
||||
if not target_tz:
|
||||
target_tz = server_timezone()
|
||||
|
||||
try:
|
||||
target_tz = pytz.timezone(str(target_tz))
|
||||
except pytz.UnknownTimeZoneError:
|
||||
target_tz = pytz.utc
|
||||
target_tz = ZoneInfo(target_tz)
|
||||
except ZoneInfoNotFoundError:
|
||||
target_tz = ZoneInfo('UTC')
|
||||
|
||||
target_time = time.replace(tzinfo=source_tz).astimezone(target_tz)
|
||||
|
||||
|
@ -20,8 +20,8 @@ from django.core.validators import URLValidator
|
||||
from django.http import Http404
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
import pytz
|
||||
from dotenv import load_dotenv
|
||||
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
||||
|
||||
from InvenTree.cache import get_cache_config, is_global_cache_enabled
|
||||
from InvenTree.config import get_boolean_setting, get_custom_file, get_setting
|
||||
@ -942,8 +942,8 @@ TIME_ZONE = get_setting('INVENTREE_TIMEZONE', 'timezone', 'UTC')
|
||||
|
||||
# Check that the timezone is valid
|
||||
try:
|
||||
pytz.timezone(TIME_ZONE)
|
||||
except pytz.exceptions.UnknownTimeZoneError: # pragma: no cover
|
||||
ZoneInfo(TIME_ZONE)
|
||||
except ZoneInfoNotFoundError: # pragma: no cover
|
||||
raise ValueError(f"Specified timezone '{TIME_ZONE}' is not valid")
|
||||
|
||||
USE_I18N = True
|
||||
|
@ -17,12 +17,12 @@ from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
|
||||
import pint.errors
|
||||
import pytz
|
||||
from djmoney.contrib.exchange.exceptions import MissingRate
|
||||
from djmoney.contrib.exchange.models import Rate, convert_money
|
||||
from djmoney.money import Money
|
||||
from maintenance_mode.core import get_maintenance_mode, set_maintenance_mode
|
||||
from sesame.utils import get_user
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
import InvenTree.conversion
|
||||
import InvenTree.format
|
||||
@ -739,7 +739,7 @@ class TestTimeFormat(TestCase):
|
||||
hour=0,
|
||||
minute=0,
|
||||
second=0,
|
||||
tzinfo=pytz.timezone('Europe/London'),
|
||||
tzinfo=ZoneInfo('Europe/London'),
|
||||
)
|
||||
|
||||
tests = [
|
||||
|
@ -10,8 +10,8 @@ from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.utils.safestring import SafeString
|
||||
|
||||
import pytz
|
||||
from PIL import Image
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
import report.models as report_models
|
||||
from build.models import Build
|
||||
@ -169,7 +169,7 @@ class ReportTagTest(TestCase):
|
||||
hour=12,
|
||||
minute=30,
|
||||
second=0,
|
||||
tzinfo=pytz.timezone('Australia/Sydney'),
|
||||
tzinfo=ZoneInfo('Australia/Sydney'),
|
||||
)
|
||||
|
||||
# Format a set of tests: timezone, format, expected
|
||||
|
Loading…
Reference in New Issue
Block a user