From a3a6f88936146b35b260b524e1eb22a324ee89b8 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 4 Apr 2021 23:59:04 -0400 Subject: Add discord.utils.utcnow() helper function to ease migration --- discord/utils.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'discord') 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) -- cgit v1.2.3