melt
is a command-line utility for working with snowflake identifiers, as used by Twitter and Discord.
A snowflake is a number used to uniquely identify a piece of data. Twitter uses it for tweets, e.g. the 1212702693736767490
in https://twitter.com/qntm/status/1212702693736767490 is a snowflake. Discord uses it for pretty much everything: users, servers, channels, messages, roles… You can access these snowflakes by going into your Advanced settings, enabling Developer Mode, then right-clicking on something to select Copy ID. Originally specified in this document, they have been used by Twitter since 2010 and by Discord since the beginning. Instagram uses a format that's based on snowflakes but slightly different, and is not supported by melt
.
A snowflake consists of 4 pieces of information: Timestamp, data center ID, worker ID, and sequence number. The interesting one is the timestamp: a representation of the date and time when the snowflake was generated, exact to the millisecond. This means that the time it was created (and thus the approximate time the tweet was sent, the Discord server was created, etc.) can be calculated from the snowflake itself. This is called melting the snowflake.
Please see the install instructions for your operating system:
If your operating system is not listed here, or if you would like to manage updates of melt
using cargo-update
, follow the instructions for building from source.
By default, melt
takes Twitter snowflakes from stdin, one per line, and converts them into UNIX timestamps with milliseconds:
$ echo 1212702693736767490 | melt
1577965827.770
Snowflakes can also be passed as command-line arguments:
$ melt 1212702693736767490
1577965827.770
The --format
(or -f
) flag can be used to modify the output format, as defined by chrono
. Additionally, the formatting directives %^d
, %^w
, and %^s
may be used to include the data center ID, worker ID, or sequence number, respectively.
$ echo 1212702693736767490 | melt -f '%d.%m.%Y %H:%M:%S'
02.01.2020 11:50:27
The flag -H
is a shorthand and specifies a format of %Y-%m-%d %H:%M:%S
:
$ echo 1212702693736767490 | melt -H
2020-01-02 11:50:27
The --timezone
(or -z
) flag can be used to change the timezone in which formatted times are displayed. The timezone must be given as a name from the Olson timezone database. By default, UTC is used. This flag has no effect on UNIX timestamps (i.e. when none of -f
, --format
, -H
are specified), which are always in UTC.
$ echo 1212702693736767490 | melt -f '%d.%m.%Y %H:%M:%S' -z Europe/Berlin
02.01.2020 12:50:27
The --epoch
(or -e
) flag can be used to change the epoch from Twitter's default to Discord's:
$ echo 86841168427495424 | melt -e discord
1309539522.641
A different epoch, given as a UNIX timestamp, may also be specified:
$ echo 0 | melt -e 0
0
The --discord-format
(or -d
) flag can be used to format the times using Discord's timestamp syntax, which can be pasted into a Discord message to get human-readable timestamps. Possible values are d
(or short-date
), D
(or long-date
), t
(or short-time
), T
(or long-time
), f
(or short-date-time
), F
(or long-date-time
), and R
(or relative
). Using this flag implies --epoch=discord
and disables the --timezone
parameter, since Discord will display the times in the system timezone of the viewer.
$ echo 86841168427495424 | melt -dF
<t:1440774947:F>
(When sent as a message, my Discord app displays the above as Friday, 28 August 2015 15:15
. The exact format may vary depending on your locale.)