Skip to content

Commit 7180770

Browse files
committed
refactor: rewrite ISODateTime converter docstring as RST
1 parent 7b609c0 commit 7180770

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

pydis_core/utils/converters.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
11
from datetime import UTC, datetime
22

33
import dateutil.parser
4-
from discord.ext.commands import BadArgument, Converter
4+
from discord.ext.commands import BadArgument, Context, Converter
55

66

77
class ISODateTime(Converter):
88
"""Converts an ISO-8601 datetime string into a datetime.datetime."""
99

10-
async def convert(self, datetime_string: str) -> datetime:
10+
async def convert(self, _context: Context, datetime_string: str) -> datetime:
1111
"""
12-
Converts a ISO-8601 `datetime_string` into a `datetime.datetime` object.
12+
Converts an ISO-8601 ``datetime_string`` into a ``datetime.datetime`` object.
1313
14-
The converter is flexible in the formats it accepts, as it uses the `isoparse` method of
15-
`dateutil.parser`. In general, it accepts datetime strings that start with a date,
14+
The converter is flexible in the formats it accepts, as it uses the :meth:`isoparse <dateutil.parser.isoparse>`
15+
method of :mod:`dateutil.parser`. In general, it accepts datetime strings that start with a date,
1616
optionally followed by a time. Specifying a timezone offset in the datetime string is
17-
supported, but the `datetime` object will be converted to UTC. If no timezone is specified, the datetime will
17+
supported, but the ``datetime`` object will be converted to UTC. If no timezone is specified, the datetime will
1818
be assumed to be in UTC already. In all cases, the returned object will have the UTC timezone.
1919
2020
See: https://dateutil.readthedocs.io/en/stable/parser.html#dateutil.parser.isoparse
2121
2222
Formats that are guaranteed to be valid by our tests are:
2323
24-
- `YYYY-mm-ddTHH:MM:SSZ` | `YYYY-mm-dd HH:MM:SSZ`
25-
- `YYYY-mm-ddTHH:MM:SS±HH:MM` | `YYYY-mm-dd HH:MM:SS±HH:MM`
26-
- `YYYY-mm-ddTHH:MM:SS±HHMM` | `YYYY-mm-dd HH:MM:SS±HHMM`
27-
- `YYYY-mm-ddTHH:MM:SS±HH` | `YYYY-mm-dd HH:MM:SS±HH`
28-
- `YYYY-mm-ddTHH:MM:SS` | `YYYY-mm-dd HH:MM:SS`
29-
- `YYYY-mm-ddTHH:MM` | `YYYY-mm-dd HH:MM`
30-
- `YYYY-mm-dd`
31-
- `YYYY-mm`
32-
- `YYYY`
33-
34-
Note: ISO-8601 specifies a `T` as the separator between the date and the time part of the
35-
datetime string. The converter accepts both a `T` and a single space character.
24+
- ``YYYY-mm-ddTHH:MM:SSZ`` | ``YYYY-mm-dd HH:MM:SSZ``
25+
- ``YYYY-mm-ddTHH:MM:SS±HH:MM`` | ``YYYY-mm-dd HH:MM:SS±HH:MM``
26+
- ``YYYY-mm-ddTHH:MM:SS±HHMM`` | ``YYYY-mm-dd HH:MM:SS±HHMM``
27+
- ``YYYY-mm-ddTHH:MM:SS±HH`` | ``YYYY-mm-dd HH:MM:SS±HH``
28+
- ``YYYY-mm-ddTHH:MM:SS`` | ``YYYY-mm-dd HH:MM:SS``
29+
- ``YYYY-mm-ddTHH:MM`` | ``YYYY-mm-dd HH:MM``
30+
- ``YYYY-mm-dd``
31+
- ``YYYY-mm``
32+
- ``YYYY``
33+
34+
.. note::
35+
36+
ISO-8601 specifies a ``T`` as the separator between the date and the time part of the
37+
datetime string. The converter accepts both a ``T`` and a single space character.
38+
39+
:rtype: datetime.datetime
3640
"""
3741
try:
3842
dt = dateutil.parser.isoparse(datetime_string)

0 commit comments

Comments
 (0)