Skip to content

Commit 0b11905

Browse files
shiftinvEnegg
andauthored
feat(utils): add s and S timestamp styles (DisnakeDev#1468)
Signed-off-by: vi <8530778+shiftinv@users.noreply.github.com> Co-authored-by: Eneg <42005170+Enegg@users.noreply.github.com>
1 parent 872e3cc commit 0b11905

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

changelog/1468.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add new ``s`` and ``S`` timestamp styles to :func:`utils.format_dt`.

disnake/utils.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,31 +1390,35 @@ def signature_has_self_param(function: Callable[..., Any]) -> bool:
13901390
return not parent.endswith(".<locals>")
13911391

13921392

1393-
TimestampStyle = Literal["f", "F", "d", "D", "t", "T", "R"]
1393+
TimestampStyle = Literal["t", "T", "d", "D", "f", "F", "s", "S", "R"]
13941394

13951395

13961396
def format_dt(dt: Union[datetime.datetime, float], /, style: TimestampStyle = "f") -> str:
1397-
"""A helper function to format a :class:`datetime.datetime`, :class:`int` or :class:`float` for presentation within Discord.
1397+
"""Format a :class:`datetime.datetime`, :class:`int` or :class:`float` (seconds) for presentation within Discord.
13981398
13991399
This allows for a locale-independent way of presenting data using Discord specific Markdown.
14001400
1401-
+-------------+----------------------------+-----------------+
1402-
| Style | Example Output | Description |
1403-
+=============+============================+=================+
1404-
| t | 22:57 | Short Time |
1405-
+-------------+----------------------------+-----------------+
1406-
| T | 22:57:58 | Long Time |
1407-
+-------------+----------------------------+-----------------+
1408-
| d | 17/05/2016 | Short Date |
1409-
+-------------+----------------------------+-----------------+
1410-
| D | 17 May 2016 | Long Date |
1411-
+-------------+----------------------------+-----------------+
1412-
| f (default) | 17 May 2016 22:57 | Short Date Time |
1413-
+-------------+----------------------------+-----------------+
1414-
| F | Tuesday, 17 May 2016 22:57 | Long Date Time |
1415-
+-------------+----------------------------+-----------------+
1416-
| R | 5 years ago | Relative Time |
1417-
+-------------+----------------------------+-----------------+
1401+
+-------------+-------------------------------+------------------------+
1402+
| Style | Example Output | Description |
1403+
+=============+===============================+========================+
1404+
| t | 22:57 | Short Time |
1405+
+-------------+-------------------------------+------------------------+
1406+
| T | 22:57:58 | Long Time |
1407+
+-------------+-------------------------------+------------------------+
1408+
| d | 17/05/2016 | Short Date |
1409+
+-------------+-------------------------------+------------------------+
1410+
| D | 17 May 2016 | Long Date |
1411+
+-------------+-------------------------------+------------------------+
1412+
| f (default) | 17 May 2016 at 22:57 | Long Date, Short Time |
1413+
+-------------+-------------------------------+------------------------+
1414+
| F | Tuesday, 17 May 2016 at 22:57 | Full Date, Short Time |
1415+
+-------------+-------------------------------+------------------------+
1416+
| s | 17/05/2016, 22:57 | Short Date, Short Time |
1417+
+-------------+-------------------------------+------------------------+
1418+
| S | 17/05/2016, 22:57:58 | Short Date, Long Time |
1419+
+-------------+-------------------------------+------------------------+
1420+
| R | 5 years ago | Relative Time |
1421+
+-------------+-------------------------------+------------------------+
14181422
14191423
Note that the exact output depends on the user's locale setting in the client. The example output
14201424
presented is using the ``en-GB`` locale.

0 commit comments

Comments
 (0)