Skip to content

Commit

Permalink
A few more 3.11 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
FasterSpeeding committed Nov 18, 2024
1 parent f88ef00 commit 61aa0a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions tanjun/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ def to_datetime(value: str, /) -> datetime.datetime:
except StopIteration:
raise ValueError("Not a valid datetime") from None

return datetime.datetime.fromtimestamp(timestamp, tz=datetime.timezone.utc)
return datetime.datetime.fromtimestamp(timestamp, tz=datetime.UTC)


_VALID_DATETIME_STYLES = frozenset(("t", "T", "d", "D", "f", "F", "R"))
Expand Down Expand Up @@ -1453,7 +1453,7 @@ def from_datetime(value: datetime.datetime | datetime.timedelta, /, *, style: st
If an invalid style is provided.
"""
if isinstance(value, datetime.timedelta):
return from_datetime(datetime.datetime.now(tz=datetime.timezone.utc) + value, style="R")
return from_datetime(datetime.datetime.now(tz=datetime.UTC) + value, style="R")

if style not in _VALID_DATETIME_STYLES:
raise ValueError(f"Invalid style: {style}")
Expand Down
12 changes: 6 additions & 6 deletions tests/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -1819,8 +1819,8 @@ def test_split_url_when_wrapped():
@pytest.mark.parametrize(
("value", "expected"),
[
("<t:123321123>", datetime.datetime(1973, 11, 28, 7, 52, 3, tzinfo=datetime.timezone.utc)),
("<t:3232133:t>", datetime.datetime(1970, 2, 7, 9, 48, 53, tzinfo=datetime.timezone.utc)),
("<t:123321123>", datetime.datetime(1973, 11, 28, 7, 52, 3, tzinfo=datetime.UTC)),
("<t:3232133:t>", datetime.datetime(1970, 2, 7, 9, 48, 53, tzinfo=datetime.UTC)),
],
)
def test_to_datetime(value: str, expected: datetime.datetime):
Expand All @@ -1834,15 +1834,15 @@ def test_to_datetime_with_invalid_values(value: str):


def test_from_datetime():
date = datetime.datetime(2021, 9, 15, 14, 16, 18, 829252, tzinfo=datetime.timezone.utc)
date = datetime.datetime(2021, 9, 15, 14, 16, 18, 829252, tzinfo=datetime.UTC)

result = tanjun.conversion.from_datetime(date, style="d")

assert result == "<t:1631715379:d>"


def test_from_datetime_with_default_style():
date = datetime.datetime(2021, 9, 15, 14, 16, 18, 829252, tzinfo=datetime.timezone.utc)
date = datetime.datetime(2021, 9, 15, 14, 16, 18, 829252, tzinfo=datetime.UTC)

result = tanjun.conversion.from_datetime(date)

Expand All @@ -1857,14 +1857,14 @@ def test_from_datetime_for_naive_datetime():


def test_from_datetime_for_invalid_style():
date = datetime.datetime.now(tz=datetime.timezone.utc)
date = datetime.datetime.now(tz=datetime.UTC)

with pytest.raises(ValueError, match="Invalid style: granddad"):
tanjun.conversion.from_datetime(date, style="granddad")


def test_from_datetime_for_time_delta():
with freezegun.freeze_time(datetime.datetime(2022, 12, 30, 6, 33, 47, 52643, tzinfo=datetime.timezone.utc)):
with freezegun.freeze_time(datetime.datetime(2022, 12, 30, 6, 33, 47, 52643, tzinfo=datetime.UTC)):
result = tanjun.conversion.from_datetime(datetime.timedelta(days=21, hours=23, minutes=32, seconds=34))

assert result == "<t:1674281181:R>"
Expand Down

0 comments on commit 61aa0a5

Please sign in to comment.