Skip to content

Commit

Permalink
v12.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
GitRon committed Feb 6, 2025
1 parent 7a38aeb commit 413d037
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 16 deletions.
4 changes: 1 addition & 3 deletions .ambient-package-update/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
),
],
maintainer=PackageMaintainer(name="Ambient Digital", url="https://ambient.digital/", email="[email protected]"),
min_coverage=68.21,
min_coverage=70.0,
development_status="5 - Production/Stable",
license=LICENSE_MIT,
license_year=2012,
Expand All @@ -31,8 +31,6 @@
dependencies=[
f"Django>={SUPPORTED_DJANGO_VERSIONS[0]}",
"python-dateutil>=2.5.3",
# We keep this until we drop Python 3.8
"pytz",
],
supported_django_versions=SUPPORTED_DJANGO_VERSIONS,
supported_python_versions=SUPPORTED_PYTHON_VERSIONS,
Expand Down
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

**12.0.1** (2025-02-06)
* Dropped `pytz` dependency and refactored some code to work with Python >= 3.9 builtins

**12.0.0** (2025-02-03)
* **Breaking change:** Renamed `STATIC_ROLE_PERMISSIONS_DISABLE_SYSTEM_CHECK` to
`STATIC_ROLE_PERMISSIONS_ENABLE_SYSTEM_CHECK` since negations are harder to understand
Expand Down
2 changes: 1 addition & 1 deletion ambient_toolbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Python toolbox of Ambient Digital containing an abundance of useful tools and gadgets."""

__version__ = "12.0.0"
__version__ = "12.0.1"
7 changes: 3 additions & 4 deletions ambient_toolbox/utils/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
import datetime
from calendar import monthrange
from typing import Optional, Union
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError

import pytz
from dateutil.relativedelta import relativedelta
from django.conf import settings
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from pytz import UnknownTimeZoneError


class DateHelper:
Expand Down Expand Up @@ -84,8 +83,8 @@ def datetime_format(target_datetime: datetime.datetime, dt_format: str) -> str:
Uses strftime, but considers timezone (only for datetime objects)
"""
try:
dt_format = target_datetime.astimezone(tz=pytz.timezone(settings.TIME_ZONE)).strftime(dt_format)
except UnknownTimeZoneError:
dt_format = target_datetime.astimezone(ZoneInfo(settings.TIME_ZONE)).strftime(dt_format)
except ZoneInfoNotFoundError:
dt_format = target_datetime.strftime(dt_format)
return dt_format

Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ license = {"file" = "LICENSE.md"}
dependencies = [
'Django>=4.2',
'python-dateutil>=2.5.3',
'pytz',
]


Expand Down
7 changes: 3 additions & 4 deletions tests/test_utils_date.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import calendar
import datetime

import pytz
from django.test import TestCase
from django.test.utils import override_settings
from freezegun import freeze_time
Expand Down Expand Up @@ -206,17 +205,17 @@ def test_get_time_from_seconds_negative_seconds(self):

@override_settings(TIME_ZONE="UTC")
def test_datetime_format_regular(self):
source_date = datetime.datetime(year=2020, month=6, day=26, hour=8, tzinfo=pytz.UTC)
source_date = datetime.datetime(year=2020, month=6, day=26, hour=8, tzinfo=datetime.UTC)
self.assertEqual(datetime_format(source_date, "%d.%m.%Y %H:%M"), "26.06.2020 08:00")

@override_settings(TIME_ZONE="Europe/Cologne")
def test_datetime_format_wrong_timezone(self):
source_date = datetime.datetime(year=2020, month=6, day=26, hour=8, tzinfo=datetime.timezone.utc)
source_date = datetime.datetime(year=2020, month=6, day=26, hour=8, tzinfo=datetime.UTC)
self.assertEqual(datetime_format(source_date, "%d.%m.%Y %H:%M"), "26.06.2020 08:00")

@override_settings(TIME_ZONE="Europe/Berlin")
def test_datetime_format_different_timezone(self):
source_date = datetime.datetime(year=2020, month=6, day=26, hour=8, tzinfo=pytz.UTC)
source_date = datetime.datetime(year=2020, month=6, day=26, hour=8, tzinfo=datetime.UTC)
self.assertEqual(datetime_format(source_date, "%d.%m.%Y %H:%M"), "26.06.2020 10:00")

@freeze_time("2022-12-14")
Expand Down
6 changes: 3 additions & 3 deletions tests/test_utils_string.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime

import pytz
from django.test import TestCase

from ambient_toolbox.utils.string import (
Expand Down Expand Up @@ -90,11 +89,12 @@ def test_date_to_string_replacement_defined(self):
self.assertEqual(date_to_string(None, "no date"), "no date")

def test_datetime_to_string_regular(self):
self.assertEqual(datetime_to_string(datetime.datetime(2020, 9, 19, 8, tzinfo=pytz.UTC)), "19.09.2020 08:00")
self.assertEqual(datetime_to_string(datetime.datetime(2020, 9, 19, 8, tzinfo=datetime.UTC)), "19.09.2020 08:00")

def test_datetime_to_string_other_format(self):
self.assertEqual(
datetime_to_string(datetime.datetime(2020, 9, 19, 8, tzinfo=pytz.UTC), str_format="%Y-%m-%d"), "2020-09-19"
datetime_to_string(datetime.datetime(2020, 9, 19, 8, tzinfo=datetime.UTC), str_format="%Y-%m-%d"),
"2020-09-19",
)

def test_datetime_to_string_replacement_undefined(self):
Expand Down

0 comments on commit 413d037

Please sign in to comment.