aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-04-04 23:59:04 -0400
committerRapptz <[email protected]>2021-04-04 23:59:04 -0400
commita3a6f88936146b35b260b524e1eb22a324ee89b8 (patch)
treee89d0c325e2cf2c4d4886416172dc237f0390a00
parentRemove special casing of MAX_ASYNCIO_SECONDS in sleep_until (diff)
downloaddiscord.py-a3a6f88936146b35b260b524e1eb22a324ee89b8.tar.xz
discord.py-a3a6f88936146b35b260b524e1eb22a324ee89b8.zip
Add discord.utils.utcnow() helper function to ease migration
-rw-r--r--discord/utils.py15
-rw-r--r--docs/api.rst2
2 files changed, 17 insertions, 0 deletions
diff --git a/discord/utils.py b/discord/utils.py
index 14470648..03478b3f 100644
--- a/discord/utils.py
+++ b/discord/utils.py
@@ -401,6 +401,21 @@ async def sleep_until(when, result=None):
delta = (when - now).total_seconds()
return await asyncio.sleep(max(delta, 0), result)
+def utcnow() -> datetime.datetime:
+ """A helper function to return an aware UTC datetime representing the current time.
+
+ This should be preferred to :func:`datetime.datetime.utcnow` since it is an aware
+ datetime, compared to the naive datetime in the standard library.
+
+ .. versionadded:: 2.0
+
+ Returns
+ --------
+ :class:`datetime.datetime`
+ The current aware datetime in UTC.
+ """
+ return datetime.datetime.now(datetime.timezone.utc)
+
def valid_icon_size(size):
"""Icons must be power of 2 within [16, 4096]."""
return not size & (size - 1) and size in range(16, 4097)
diff --git a/docs/api.rst b/docs/api.rst
index 044f402f..b328ab22 100644
--- a/docs/api.rst
+++ b/docs/api.rst
@@ -922,6 +922,8 @@ Utility Functions
.. autofunction:: discord.utils.sleep_until
+.. autofunction:: discord.utils.utcnow
+
.. _discord-api-enums:
Enumerations