From a544a6d020448e582432b1bf2a958d69ee0b658e Mon Sep 17 00:00:00 2001 From: Andrei Date: Tue, 25 Apr 2017 06:55:32 -0700 Subject: [PATCH] Add snowflake-utils from_datetime and from_timestamp --- disco/util/snowflake.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/disco/util/snowflake.py b/disco/util/snowflake.py index b2f512f..2fa915d 100644 --- a/disco/util/snowflake.py +++ b/disco/util/snowflake.py @@ -20,6 +20,14 @@ def to_unix_ms(snowflake): return (int(snowflake) >> 22) + DISCORD_EPOCH +def from_datetime(date): + return from_timestamp(int(date.isoformat('%s'))) + + +def from_timestamp(ts): + return long(ts * 1000.0 - DISCORD_EPOCH) << 22 + + def to_snowflake(i): if isinstance(i, six.integer_types): return i