Sunbake.Snowflake (Sunbake v0.2.4) View Source

Module for assisting with Discord Snowflakes.

Link to this section Summary

Functions

Cast the integer to its snowflake representation.

Dumps a string version of the snowflake

Callback implementation for Ecto.Type.embed_as/1.

Callback implementation for Ecto.Type.equal?/2.

Convers an elxiir %DateTime{} into its snowflake form.

Callback implementation for Ecto.Type.type/0.

Link to this section Types

Specs

t() :: 0..18_446_744_073_709_551_615

Link to this section Functions

Cast the integer to its snowflake representation.

## Examples

  iex> Sunbake.Snowflake.cast(381887113391505410)
  {:ok, 381887113391505410}

  iex> Sunbake.Snowflake.cast("381887113391505410")
  {:ok, 381887113391505410}

  iex> Sunbake.Snowflake.cast(DateTime.now())

  iex> Sunbake.cast("bad_value")
  :error

Dumps a string version of the snowflake

Examples

iex> Sunbake.Snowflake.dump(381887113391505410)
{:ok, 381887113391505410}

Callback implementation for Ecto.Type.embed_as/1.

Callback implementation for Ecto.Type.equal?/2.

Link to this macro

is_snowflake(term)

View Source (macro)

Convers an elxiir %DateTime{} into its snowflake form.

Obviously this does not include the non time components of the snowflake. But it does allow you to order a datetime with snowflakes.

## Examples

  iex> DateTime.now!("Etc/UTC") |> Sunbake.Snowflake.from_datetime()
  "381887113391505410"

Specs

type() :: :integer

Callback implementation for Ecto.Type.type/0.