def deserialize_typing_start_event( self, shard: gateway_shard.GatewayShard, payload: data_binding.JSONObject) -> typing_events.TypingEvent: channel_id = snowflakes.Snowflake(payload["channel_id"]) user_id = snowflakes.Snowflake(payload["user_id"]) # Turns out that this endpoint uses seconds rather than milliseconds. timestamp = time.unix_epoch_to_datetime(payload["timestamp"], is_millis=False) if "guild_id" in payload: guild_id = snowflakes.Snowflake(payload["guild_id"]) member = self._app.entity_factory.deserialize_member( payload["member"], guild_id=guild_id) return typing_events.GuildTypingEvent( app=self._app, shard=shard, channel_id=channel_id, guild_id=guild_id, timestamp=timestamp, user=member, ) return typing_events.DMTypingEvent(app=self._app, shard=shard, channel_id=channel_id, user_id=user_id, timestamp=timestamp)
def test_parse_unix_epoch_to_datetime(): unix_timestamp = 1457991678956 expected_timestamp = datetime.datetime(2016, 3, 14, 21, 41, 18, 956000, tzinfo=datetime.timezone.utc) assert time.unix_epoch_to_datetime(unix_timestamp) == expected_timestamp
def test_unix_epoch_to_datetime_with_out_of_range_negative_timestamp(): assert time.unix_epoch_to_datetime( -996877846784536) == datetime.datetime.min