Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions discord/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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"<t:{int(dt.timestamp())}>"
return f"<t:{int(dt.timestamp())}:{style}>"
Expand Down