aboutsummaryrefslogtreecommitdiff
path: root/discord/utils.py
diff options
context:
space:
mode:
authorKhazhismel <[email protected]>2016-03-05 16:00:21 -0500
committerRapptz <[email protected]>2016-03-06 03:40:16 -0500
commit612aa4d107f90298ea680f92fba2491228fe3c74 (patch)
treec05bbc7748c118a55354cce5adcd58c68d5a873b /discord/utils.py
parentRemove Server.me from __slots__ since it is a property now. (diff)
downloaddiscord.py-612aa4d107f90298ea680f92fba2491228fe3c74.tar.xz
discord.py-612aa4d107f90298ea680f92fba2491228fe3c74.zip
Add util method to extract creation date from discord ids
Diffstat (limited to 'discord/utils.py')
-rw-r--r--discord/utils.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/discord/utils.py b/discord/utils.py
index dc8c941d..0440c468 100644
--- a/discord/utils.py
+++ b/discord/utils.py
@@ -31,6 +31,7 @@ from base64 import b64encode
import asyncio
import json
+DISCORD_EPOCH = 1420070400000
class cached_property:
def __init__(self, function):
@@ -73,6 +74,12 @@ def parse_time(timestamp):
return datetime.datetime(*map(int, re_split(r'[^\d]', timestamp.replace('+00:00', ''))))
return None
+def snowflake_time(id):
+ '''
+ Returns the creation date of a discord id.
+ '''
+ return datetime.datetime.utcfromtimestamp(((int(id) >> 22) + DISCORD_EPOCH) / 1000)
+
def find(predicate, seq):
"""A helper to return the first element found in the sequence
that meets the predicate. For example: ::