Packages
kirala_l4u
0.1.1
An embedded lisp interpreter based on the gleam implementation of MAL lisp.
Current section
Files
Jump to
Current section
Files
src/l4u@bif_datetime.erl
-module(l4u@bif_datetime).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([start/0, epoch/0, datetime_format/2, bif_datetime_def/0]).
-spec start() -> nil.
start() ->
l4u@bif_datetime_ffi:start().
-spec epoch() -> integer().
epoch() ->
l4u@bif_datetime_ffi:epoch().
-spec bif_now(list(l4u@l4u_type:expr()), l4u@l4u_type:env()) -> l4u@l4u_type:expr().
bif_now(Exprs, Env) ->
[] = case Exprs of
[] -> Exprs;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"l4u/bif_datetime"/utf8>>,
function => <<"bif_now"/utf8>>,
line => 41})
end,
Timestamp32 = l4u@bif_datetime_ffi:epoch(),
{with_env, {int, Timestamp32}, Env}.
-spec datetime_format(integer(), binary()) -> binary().
datetime_format(Timestamp, Format) ->
l4u@bif_datetime_ffi:datetime_format(Timestamp, Format).
-spec bif_datetime_format(list(l4u@l4u_type:expr()), l4u@l4u_type:env()) -> l4u@l4u_type:expr().
bif_datetime_format(Exprs, Env) ->
[{int, Timestamp}, Format] = case Exprs of
[{int, _}, _] -> Exprs;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"l4u/bif_datetime"/utf8>>,
function => <<"bif_datetime_format"/utf8>>,
line => 54})
end,
Str_format = l4u@l4u_core:pstr(Format),
Formatted = l4u@bif_datetime_ffi:datetime_format(Timestamp, Str_format),
{with_env, {string, Formatted}, Env}.
-spec bif_datetime_def() -> list({binary(), l4u@l4u_type:expr()}).
bif_datetime_def() ->
l4u@bif_datetime_ffi:start(),
Bif = fun(Name, F) -> {Name, {bif, l4u@l4u_core:description(Name), F}} end,
Bsf = fun(Name@1, F@1) ->
{Name@1, {bispform, l4u@l4u_core:description(Name@1), F@1}}
end,
[Bif(<<"now"/utf8>>, fun bif_now/2),
Bif(<<"datetime-format"/utf8>>, fun bif_datetime_format/2)].