|
50 | 50 | )
|
51 | 51 |
|
52 | 52 | from ..errors import HTTPException
|
53 |
| -from .public import basic_autocomplete, generate_snowflake, utcnow, snowflake_time, oauth_url, Undefined, MISSING |
| 53 | +from .public import ( |
| 54 | + basic_autocomplete, |
| 55 | + generate_snowflake, |
| 56 | + utcnow, |
| 57 | + snowflake_time, |
| 58 | + oauth_url, |
| 59 | + Undefined, |
| 60 | + MISSING, |
| 61 | + format_dt, |
| 62 | +) |
54 | 63 |
|
55 | 64 | try:
|
56 | 65 | import msgspec
|
@@ -603,53 +612,3 @@ def as_chunks(iterator: _Iter[T], max_size: int) -> _Iter[list[T]]:
|
603 | 612 | if isinstance(iterator, AsyncIterator):
|
604 | 613 | return _achunk(iterator, max_size)
|
605 | 614 | return _chunk(iterator, max_size)
|
606 |
| - |
607 |
| - |
608 |
| -TimestampStyle = Literal["f", "F", "d", "D", "t", "T", "R"] |
609 |
| - |
610 |
| - |
611 |
| -def format_dt(dt: datetime.datetime | datetime.time, /, style: TimestampStyle | None = None) -> str: |
612 |
| - """A helper function to format a :class:`datetime.datetime` for presentation within Discord. |
613 |
| -
|
614 |
| - This allows for a locale-independent way of presenting data using Discord specific Markdown. |
615 |
| -
|
616 |
| - +-------------+----------------------------+-----------------+ |
617 |
| - | Style | Example Output | Description | |
618 |
| - +=============+============================+=================+ |
619 |
| - | t | 22:57 | Short Time | |
620 |
| - +-------------+----------------------------+-----------------+ |
621 |
| - | T | 22:57:58 | Long Time | |
622 |
| - +-------------+----------------------------+-----------------+ |
623 |
| - | d | 17/05/2016 | Short Date | |
624 |
| - +-------------+----------------------------+-----------------+ |
625 |
| - | D | 17 May 2016 | Long Date | |
626 |
| - +-------------+----------------------------+-----------------+ |
627 |
| - | f (default) | 17 May 2016 22:57 | Short Date Time | |
628 |
| - +-------------+----------------------------+-----------------+ |
629 |
| - | F | Tuesday, 17 May 2016 22:57 | Long Date Time | |
630 |
| - +-------------+----------------------------+-----------------+ |
631 |
| - | R | 5 years ago | Relative Time | |
632 |
| - +-------------+----------------------------+-----------------+ |
633 |
| -
|
634 |
| - Note that the exact output depends on the user's locale setting in the client. The example output |
635 |
| - presented is using the ``en-GB`` locale. |
636 |
| -
|
637 |
| - .. versionadded:: 2.0 |
638 |
| -
|
639 |
| - Parameters |
640 |
| - ---------- |
641 |
| - dt: Union[:class:`datetime.datetime`, :class:`datetime.time`] |
642 |
| - The datetime to format. |
643 |
| - style: :class:`str`R |
644 |
| - The style to format the datetime with. |
645 |
| -
|
646 |
| - Returns |
647 |
| - ------- |
648 |
| - :class:`str` |
649 |
| - The formatted string. |
650 |
| - """ |
651 |
| - if isinstance(dt, datetime.time): |
652 |
| - dt = datetime.datetime.combine(datetime.datetime.now(), dt) |
653 |
| - if style is None: |
654 |
| - return f"<t:{int(dt.timestamp())}>" |
655 |
| - return f"<t:{int(dt.timestamp())}:{style}>" |
0 commit comments