Skip to content

Commit 0e30448

Browse files
feat: ✨ Support formatting datetime.time in format_dt (Pycord-Development#2747)
Co-authored-by: plun1331 <[email protected]>
1 parent 46adb25 commit 0e30448

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ These changes are available on the `master` branch, but have not yet been releas
4949
([#2579](https://github.com/Pycord-Development/pycord/pull/2579))
5050
- Added new `Subscription` object and related methods/events.
5151
([#2564](https://github.com/Pycord-Development/pycord/pull/2564))
52-
- Added ability to change the API's base URL with `Route.API_BASE_URL`.
52+
- Added the ability to change the API's base URL with `Route.API_BASE_URL`.
5353
([#2714](https://github.com/Pycord-Development/pycord/pull/2714))
54+
- Added the ability to pass a `datetime.time` object to `format_dt`
55+
([#2747](https://github.com/Pycord-Development/pycord/pull/2747))
5456

5557
### Fixed
5658

discord/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,9 @@ def resolve_annotation(
12361236
TimestampStyle = Literal["f", "F", "d", "D", "t", "T", "R"]
12371237

12381238

1239-
def format_dt(dt: datetime.datetime, /, style: TimestampStyle | None = None) -> str:
1239+
def format_dt(
1240+
dt: datetime.datetime | datetime.time, /, style: TimestampStyle | None = None
1241+
) -> str:
12401242
"""A helper function to format a :class:`datetime.datetime` for presentation within Discord.
12411243
12421244
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) ->
12661268
12671269
Parameters
12681270
----------
1269-
dt: :class:`datetime.datetime`
1271+
dt: Union[:class:`datetime.datetime`, :class:`datetime.time`]
12701272
The datetime to format.
12711273
style: :class:`str`
12721274
The style to format the datetime with.
@@ -1276,6 +1278,8 @@ def format_dt(dt: datetime.datetime, /, style: TimestampStyle | None = None) ->
12761278
:class:`str`
12771279
The formatted string.
12781280
"""
1281+
if isinstance(dt, datetime.time):
1282+
dt = datetime.datetime.combine(datetime.datetime.now(), dt)
12791283
if style is None:
12801284
return f"<t:{int(dt.timestamp())}>"
12811285
return f"<t:{int(dt.timestamp())}:{style}>"

0 commit comments

Comments
 (0)