Packages

A Gleam library for building Discord webhook payloads safely.

Current section

Files

Jump to
kitazith src kitazith@message_formatting@timestamp.erl
Raw

src/kitazith@message_formatting@timestamp.erl

-module(kitazith@message_formatting@timestamp).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/kitazith/message_formatting/timestamp.gleam").
-export([format/2, default/1]).
-export_type([style/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type style() :: default |
short_time |
medium_time |
short_date |
long_date |
long_date_short_time |
full_date_short_time |
short_date_short_time |
short_date_medium_time |
relative_time.
-file("src/kitazith/message_formatting/timestamp.gleam", 41).
-spec style_code(style()) -> binary().
style_code(Style) ->
case Style of
default ->
<<""/utf8>>;
short_time ->
<<"t"/utf8>>;
medium_time ->
<<"T"/utf8>>;
short_date ->
<<"d"/utf8>>;
long_date ->
<<"D"/utf8>>;
long_date_short_time ->
<<"f"/utf8>>;
full_date_short_time ->
<<"F"/utf8>>;
short_date_short_time ->
<<"s"/utf8>>;
short_date_medium_time ->
<<"S"/utf8>>;
relative_time ->
<<"R"/utf8>>
end.
-file("src/kitazith/message_formatting/timestamp.gleam", 22).
?DOC(" Format Unix seconds as a Discord message timestamp.\n").
-spec format(integer(), style()) -> binary().
format(Seconds, Style) ->
case Style of
default ->
erlang:list_to_binary(
[<<"<t:"/utf8>>,
erlang:integer_to_binary(Seconds),
<<">"/utf8>>]
);
_ ->
erlang:list_to_binary(
[<<"<t:"/utf8>>,
erlang:integer_to_binary(Seconds),
<<":"/utf8>>,
style_code(Style),
<<">"/utf8>>]
)
end.
-file("src/kitazith/message_formatting/timestamp.gleam", 37).
?DOC(" Format Unix seconds using Discord's default timestamp rendering.\n").
-spec default(integer()) -> binary().
default(Seconds) ->
format(Seconds, default).