Browse Source

Add snowflake-utils from_datetime and from_timestamp

pull/27/head
Andrei 8 years ago
parent
commit
a544a6d020
  1. 8
      disco/util/snowflake.py

8
disco/util/snowflake.py

@ -20,6 +20,14 @@ def to_unix_ms(snowflake):
return (int(snowflake) >> 22) + DISCORD_EPOCH 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): def to_snowflake(i):
if isinstance(i, six.integer_types): if isinstance(i, six.integer_types):
return i return i

Loading…
Cancel
Save