diff --git a/CHANGELOG.md b/CHANGELOG.md index 36d9e65d29..38725e4141 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,8 +49,10 @@ These changes are available on the `master` branch, but have not yet been releas ([#2579](https://github.com/Pycord-Development/pycord/pull/2579)) - Added new `Subscription` object and related methods/events. ([#2564](https://github.com/Pycord-Development/pycord/pull/2564)) -- Added ability to change the API's base URL with `Route.API_BASE_URL`. +- Added the ability to change the API's base URL with `Route.API_BASE_URL`. ([#2714](https://github.com/Pycord-Development/pycord/pull/2714)) +- Added the ability to pass a `datetime.time` object to `format_dt` + ([#2747](https://github.com/Pycord-Development/pycord/pull/2747)) ### Fixed diff --git a/discord/utils.py b/discord/utils.py index c04ef0b0bd..363d339391 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -1236,7 +1236,9 @@ def resolve_annotation( TimestampStyle = Literal["f", "F", "d", "D", "t", "T", "R"] -def format_dt(dt: datetime.datetime, /, style: TimestampStyle | None = None) -> str: +def format_dt( + dt: datetime.datetime | datetime.time, /, style: TimestampStyle | None = None +) -> str: """A helper function to format a :class:`datetime.datetime` for presentation within Discord. This allows for a locale-independent way of presenting data using Discord specific Markdown. @@ -1266,7 +1268,7 @@ def format_dt(dt: datetime.datetime, /, style: TimestampStyle | None = None) -> Parameters ---------- - dt: :class:`datetime.datetime` + dt: Union[:class:`datetime.datetime`, :class:`datetime.time`] The datetime to format. style: :class:`str` The style to format the datetime with. @@ -1276,6 +1278,8 @@ def format_dt(dt: datetime.datetime, /, style: TimestampStyle | None = None) -> :class:`str` The formatted string. """ + if isinstance(dt, datetime.time): + dt = datetime.datetime.combine(datetime.datetime.now(), dt) if style is None: return f"" return f""