Current section
Files
Jump to
Current section
Files
src/tempo@datetime.erl
-module(tempo@datetime).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([new/3, now_utc/0, from_string/1, literal/1, to_string/1, parse/2, parse_any/1, from_unix_utc/1, from_unix_milli_utc/1, from_unix_micro_utc/1, from_dynamic_string/1, from_dynamic_unix_utc/1, from_dynamic_unix_milli_utc/1, from_dynamic_unix_micro_utc/1, get_date/1, get_time/1, get_offset/1, format/2, drop_offset/1, drop_time/1, to_second_precision/1, to_milli_precision/1, to_micro_precision/1, to_nano_precision/1, add/2, apply_offset/1, to_unix_utc/1, to_unix_milli_utc/1, to_unix_micro_utc/1, to_utc/1, compare/2, is_earlier/2, is_earlier_or_equal/2, is_equal/2, is_later/2, is_later_or_equal/2, as_period/2, difference_from/2, difference/2, subtract/2, to_offset/2, to_local/1, now_local/0, now_text/0, to_local_time/1, to_local_date/1, time_left_in_day/1]).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 77).
-spec new(tempo:date(), tempo:time(), tempo:offset()) -> tempo:date_time().
new(Date, Time, Offset) ->
tempo:datetime(tempo@naive_datetime:new(Date, Time), Offset).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 142).
-spec now_utc() -> tempo:date_time().
now_utc() ->
{Now_monotonic, Now_unique} = tempo:now_monounique(),
Now_ts_nano = tempo_ffi:now(),
new(
tempo@date:from_unix_utc(Now_ts_nano div 1000000000),
begin
_pipe = tempo@time:from_unix_nano_utc(Now_ts_nano),
tempo:time_set_mono(
_pipe,
{some, Now_monotonic},
{some, Now_unique}
)
end,
{offset, 0}
).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 217).
-spec split_time_and_offset(binary()) -> {ok, {binary(), binary()}} |
{error, tempo:error()}.
split_time_and_offset(Time_with_offset) ->
case gleam@string:slice(Time_with_offset, -1, 1) of
<<"Z"/utf8>> ->
_pipe = {gleam@string:drop_right(Time_with_offset, 1), <<"Z"/utf8>>},
{ok, _pipe};
<<"z"/utf8>> ->
_pipe@1 = {gleam@string:drop_right(Time_with_offset, 1),
<<"Z"/utf8>>},
{ok, _pipe@1};
_ ->
case gleam@string:split(Time_with_offset, <<"-"/utf8>>) of
[Time, Offset] ->
_pipe@2 = {Time, <<"-"/utf8, Offset/binary>>},
{ok, _pipe@2};
_ ->
case gleam@string:split(Time_with_offset, <<"+"/utf8>>) of
[Time@1, Offset@1] ->
_pipe@3 = {Time@1, <<"+"/utf8, Offset@1/binary>>},
{ok, _pipe@3};
_ ->
{error, date_time_invalid_format}
end
end
end.
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 185).
-spec from_string(binary()) -> {ok, tempo:date_time()} | {error, tempo:error()}.
from_string(Datetime) ->
Split_dt = case gleam_stdlib:contains_string(Datetime, <<"T"/utf8>>) of
true ->
gleam@string:split(Datetime, <<"T"/utf8>>);
false ->
gleam@string:split(Datetime, <<" "/utf8>>)
end,
case Split_dt of
[Date, Time] ->
gleam@result:'try'(
tempo@date:from_string(Date),
fun(Date@1) ->
gleam@result:'try'(
split_time_and_offset(Time),
fun(_use0) ->
{Time@1, Offset} = _use0,
gleam@result:'try'(
tempo@time:from_string(Time@1),
fun(Time@2) ->
gleam@result:map(
tempo@offset:from_string(Offset),
fun(Offset@1) ->
new(Date@1, Time@2, Offset@1)
end
)
end
)
end
)
end
);
[Date@2] ->
_pipe = tempo@date:from_string(Date@2),
gleam@result:map(
_pipe,
fun(_capture) ->
new(
_capture,
tempo:time(0, 0, 0, 0, sec, none, none),
{offset, 0}
)
end
);
_ ->
{error, date_time_invalid_format}
end.
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 99).
-spec literal(binary()) -> tempo:date_time().
literal(Datetime) ->
case from_string(Datetime) of
{ok, Datetime@1} ->
Datetime@1;
{error, date_time_invalid_format} ->
erlang:error(#{gleam_error => panic,
message => <<"Invalid datetime literal format"/utf8>>,
module => <<"tempo/datetime"/utf8>>,
function => <<"literal"/utf8>>,
line => 103});
{error, date_out_of_bounds} ->
erlang:error(#{gleam_error => panic,
message => <<"Invalid date in datetime literal value"/utf8>>,
module => <<"tempo/datetime"/utf8>>,
function => <<"literal"/utf8>>,
line => 105});
{error, time_out_of_bounds} ->
erlang:error(#{gleam_error => panic,
message => <<"Invalid time indatetime literal value"/utf8>>,
module => <<"tempo/datetime"/utf8>>,
function => <<"literal"/utf8>>,
line => 107});
{error, _} ->
erlang:error(#{gleam_error => panic,
message => <<"Invalid datetime literal"/utf8>>,
module => <<"tempo/datetime"/utf8>>,
function => <<"literal"/utf8>>,
line => 108})
end.
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 245).
-spec to_string(tempo:date_time()) -> binary().
to_string(Datetime) ->
<<(begin
_pipe = Datetime,
_pipe@1 = tempo:datetime_get_naive(_pipe),
tempo@naive_datetime:to_string(_pipe@1)
end)/binary,
(case begin
_pipe@2 = Datetime,
_pipe@3 = tempo:datetime_get_offset(_pipe@2),
tempo:offset_get_minutes(_pipe@3)
end of
0 ->
<<"Z"/utf8>>;
_ ->
_pipe@4 = Datetime,
_pipe@5 = tempo:datetime_get_offset(_pipe@4),
tempo@offset:to_string(_pipe@5)
end)/binary>>.
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 285).
-spec parse(binary(), binary()) -> {ok, tempo:date_time()} |
{error, tempo:error()}.
parse(Str, Fmt) ->
gleam@result:'try'(
tempo:consume_format(Str, Fmt),
fun(_use0) ->
{Parts, _} = _use0,
gleam@result:'try'(
tempo:find_date(Parts),
fun(Date) ->
gleam@result:'try'(
tempo:find_time(Parts),
fun(Time) ->
gleam@result:'try'(
tempo:find_offset(Parts),
fun(Offset) -> {ok, new(Date, Time, Offset)} end
)
end
)
end
)
end
).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 312).
-spec parse_any(binary()) -> {ok, tempo:date_time()} | {error, tempo:error()}.
parse_any(Str) ->
case tempo:parse_any(Str) of
{ok, {{some, Date}, {some, Time}, {some, Offset}}} ->
{ok, new(Date, Time, Offset)};
{ok, {_, _, none}} ->
{error, parse_missing_offset};
{ok, {_, none, _}} ->
{error, parse_missing_time};
{ok, {none, _, _}} ->
{error, parse_missing_date};
{error, Err} ->
{error, Err}
end.
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 424).
-spec from_unix_utc(integer()) -> tempo:date_time().
from_unix_utc(Unix_ts) ->
new(
tempo@date:from_unix_utc(Unix_ts),
tempo@time:from_unix_utc(Unix_ts),
{offset, 0}
).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 454).
-spec from_unix_milli_utc(integer()) -> tempo:date_time().
from_unix_milli_utc(Unix_ts) ->
new(
tempo@date:from_unix_milli_utc(Unix_ts),
tempo@time:from_unix_milli_utc(Unix_ts),
{offset, 0}
).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 486).
-spec from_unix_micro_utc(integer()) -> tempo:date_time().
from_unix_micro_utc(Unix_ts) ->
new(
tempo@date:from_unix_micro_utc(Unix_ts),
tempo@time:from_unix_micro_utc(Unix_ts),
{offset, 0}
).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 532).
-spec from_dynamic_string(gleam@dynamic:dynamic_()) -> {ok, tempo:date_time()} |
{error, list(gleam@dynamic:decode_error())}.
from_dynamic_string(Dynamic_string) ->
gleam@result:'try'(
gleam@dynamic:string(Dynamic_string),
fun(Dt) -> case from_string(Dt) of
{ok, Datetime} ->
{ok, Datetime};
{error, Tempo_error} ->
{error,
[{decode_error,
<<"tempo.DateTime"/utf8>>,
<<(case Tempo_error of
date_time_invalid_format ->
<<"Invalid format: "/utf8>>;
naive_date_time_invalid_format ->
<<"Invalid format: "/utf8>>;
date_invalid_format ->
<<"Invalid format: "/utf8>>;
time_invalid_format ->
<<"Invalid format: "/utf8>>;
offset_invalid_format ->
<<"Invalid format: "/utf8>>;
date_out_of_bounds ->
<<"Date out of bounds: "/utf8>>;
month_out_of_bounds ->
<<"Month out of bounds: "/utf8>>;
time_out_of_bounds ->
<<"Time out of bounds: "/utf8>>;
offset_out_of_bounds ->
<<"Offset out of bounds: "/utf8>>;
_ ->
<<""/utf8>>
end)/binary, Dt/binary>>,
[]}]}
end end
).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 584).
-spec from_dynamic_unix_utc(gleam@dynamic:dynamic_()) -> {ok, tempo:date_time()} |
{error, list(gleam@dynamic:decode_error())}.
from_dynamic_unix_utc(Dynamic_ts) ->
gleam@result:map(
gleam@dynamic:int(Dynamic_ts),
fun(Dt) -> from_unix_utc(Dt) end
).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 614).
-spec from_dynamic_unix_milli_utc(gleam@dynamic:dynamic_()) -> {ok,
tempo:date_time()} |
{error, list(gleam@dynamic:decode_error())}.
from_dynamic_unix_milli_utc(Dynamic_ts) ->
gleam@result:map(
gleam@dynamic:int(Dynamic_ts),
fun(Dt) -> from_unix_milli_utc(Dt) end
).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 644).
-spec from_dynamic_unix_micro_utc(gleam@dynamic:dynamic_()) -> {ok,
tempo:date_time()} |
{error, list(gleam@dynamic:decode_error())}.
from_dynamic_unix_micro_utc(Dynamic_ts) ->
gleam@result:map(
gleam@dynamic:int(Dynamic_ts),
fun(Dt) -> from_unix_micro_utc(Dt) end
).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 661).
-spec get_date(tempo:date_time()) -> tempo:date().
get_date(Datetime) ->
_pipe = Datetime,
_pipe@1 = tempo:datetime_get_naive(_pipe),
tempo:naive_datetime_get_date(_pipe@1).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 674).
-spec get_time(tempo:date_time()) -> tempo:time().
get_time(Datetime) ->
_pipe = Datetime,
_pipe@1 = tempo:datetime_get_naive(_pipe),
tempo:naive_datetime_get_time(_pipe@1).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 687).
-spec get_offset(tempo:date_time()) -> tempo:offset().
get_offset(Datetime) ->
_pipe = Datetime,
tempo:datetime_get_offset(_pipe).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 391).
-spec replace_format(binary(), tempo:date_time()) -> binary().
replace_format(Content, Datetime) ->
Offset = begin
_pipe = Datetime,
get_offset(_pipe)
end,
case Content of
<<"z"/utf8>> ->
case begin
_pipe@1 = Offset,
tempo:offset_get_minutes(_pipe@1)
end of
0 ->
<<"Z"/utf8>>;
_ ->
Str_offset = begin
_pipe@2 = Offset,
tempo@offset:to_string(_pipe@2)
end,
case begin
_pipe@3 = Str_offset,
gleam@string:split(_pipe@3, <<":"/utf8>>)
end of
[Hours, <<"00"/utf8>>] ->
Hours;
_ ->
Str_offset
end
end;
<<"Z"/utf8>> ->
_pipe@4 = Offset,
tempo@offset:to_string(_pipe@4);
<<"ZZ"/utf8>> ->
_pipe@5 = Offset,
_pipe@6 = tempo@offset:to_string(_pipe@5),
gleam@string:replace(_pipe@6, <<":"/utf8>>, <<""/utf8>>);
_ ->
Content
end.
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 364).
-spec format(tempo:date_time(), binary()) -> binary().
format(Datetime, Fmt) ->
_assert_subject = gleam@regex:from_string(
<<"\\[([^\\]]+)\\]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|z|SSSSS|SSSS|SSS|."/utf8>>
),
{ok, Re} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"tempo/datetime"/utf8>>,
function => <<"format"/utf8>>,
line => 365})
end,
_pipe = gleam@regex:scan(Re, Fmt),
_pipe@1 = lists:reverse(_pipe),
_pipe@7 = gleam@list:fold(_pipe@1, [], fun(Acc, Match) -> case Match of
{match, Content, []} ->
[begin
_pipe@2 = Content,
_pipe@4 = tempo@date:replace_format(
_pipe@2,
begin
_pipe@3 = Datetime,
get_date(_pipe@3)
end
),
_pipe@6 = tempo@time:replace_format(
_pipe@4,
begin
_pipe@5 = Datetime,
get_time(_pipe@5)
end
),
replace_format(_pipe@6, Datetime)
end |
Acc];
{match, _, [{some, Sub}]} ->
[Sub | Acc];
{match, Content@1, _} ->
[Content@1 | Acc]
end end),
gleam@string:join(_pipe@7, <<""/utf8>>).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 700).
-spec drop_offset(tempo:date_time()) -> tempo:naive_date_time().
drop_offset(Datetime) ->
_pipe = Datetime,
tempo:datetime_get_naive(_pipe).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 713).
-spec drop_time(tempo:date_time()) -> tempo:date_time().
drop_time(Datetime) ->
tempo:datetime(
tempo@naive_datetime:drop_time(
begin
_pipe = Datetime,
tempo:datetime_get_naive(_pipe)
end
),
begin
_pipe@1 = Datetime,
tempo:datetime_get_offset(_pipe@1)
end
).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 935).
-spec to_second_precision(tempo:date_time()) -> tempo:date_time().
to_second_precision(Datetime) ->
new(
begin
_pipe = Datetime,
_pipe@1 = tempo:datetime_get_naive(_pipe),
tempo:naive_datetime_get_date(_pipe@1)
end,
begin
_pipe@2 = Datetime,
_pipe@3 = tempo:datetime_get_naive(_pipe@2),
_pipe@4 = tempo:naive_datetime_get_time(_pipe@3),
tempo@time:to_second_precision(_pipe@4)
end,
begin
_pipe@5 = Datetime,
tempo:datetime_get_offset(_pipe@5)
end
).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 957).
-spec to_milli_precision(tempo:date_time()) -> tempo:date_time().
to_milli_precision(Datetime) ->
new(
begin
_pipe = Datetime,
_pipe@1 = tempo:datetime_get_naive(_pipe),
tempo:naive_datetime_get_date(_pipe@1)
end,
begin
_pipe@2 = Datetime,
_pipe@3 = tempo:datetime_get_naive(_pipe@2),
_pipe@4 = tempo:naive_datetime_get_time(_pipe@3),
tempo@time:to_milli_precision(_pipe@4)
end,
begin
_pipe@5 = Datetime,
tempo:datetime_get_offset(_pipe@5)
end
).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 979).
-spec to_micro_precision(tempo:date_time()) -> tempo:date_time().
to_micro_precision(Datetime) ->
new(
begin
_pipe = Datetime,
_pipe@1 = tempo:datetime_get_naive(_pipe),
tempo:naive_datetime_get_date(_pipe@1)
end,
begin
_pipe@2 = Datetime,
_pipe@3 = tempo:datetime_get_naive(_pipe@2),
_pipe@4 = tempo:naive_datetime_get_time(_pipe@3),
tempo@time:to_micro_precision(_pipe@4)
end,
begin
_pipe@5 = Datetime,
tempo:datetime_get_offset(_pipe@5)
end
).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 1001).
-spec to_nano_precision(tempo:date_time()) -> tempo:date_time().
to_nano_precision(Datetime) ->
new(
begin
_pipe = Datetime,
_pipe@1 = tempo:datetime_get_naive(_pipe),
tempo:naive_datetime_get_date(_pipe@1)
end,
begin
_pipe@2 = Datetime,
_pipe@3 = tempo:datetime_get_naive(_pipe@2),
_pipe@4 = tempo:naive_datetime_get_time(_pipe@3),
tempo@time:to_nano_precision(_pipe@4)
end,
begin
_pipe@5 = Datetime,
tempo:datetime_get_offset(_pipe@5)
end
).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 1229).
-spec add(tempo:date_time(), tempo:duration()) -> tempo:date_time().
add(Datetime, Duration_to_add) ->
_pipe = Datetime,
_pipe@1 = drop_offset(_pipe),
_pipe@2 = tempo@naive_datetime:add(_pipe@1, Duration_to_add),
tempo@naive_datetime:set_offset(
_pipe@2,
begin
_pipe@3 = Datetime,
tempo:datetime_get_offset(_pipe@3)
end
).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 731).
-spec apply_offset(tempo:date_time()) -> tempo:naive_date_time().
apply_offset(Datetime) ->
Original_time = begin
_pipe = tempo:datetime_get_naive(Datetime),
tempo:naive_datetime_get_time(_pipe)
end,
Applied = begin
_pipe@1 = Datetime,
_pipe@3 = add(
_pipe@1,
tempo@offset:to_duration(
begin
_pipe@2 = Datetime,
tempo:datetime_get_offset(_pipe@2)
end
)
),
drop_offset(_pipe@3)
end,
tempo:naive_datetime(
tempo@naive_datetime:get_date(Applied),
begin
_pipe@4 = tempo@naive_datetime:get_time(Applied),
tempo:time_set_mono(
_pipe@4,
tempo:time_get_mono(Original_time),
tempo:time_get_unique(Original_time)
)
end
).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 437).
-spec to_unix_utc(tempo:date_time()) -> integer().
to_unix_utc(Datetime) ->
Utc_dt = begin
_pipe = Datetime,
apply_offset(_pipe)
end,
tempo@date:to_unix_utc(
begin
_pipe@1 = Utc_dt,
tempo:naive_datetime_get_date(_pipe@1)
end
)
+ (tempo@time:to_nanoseconds(
begin
_pipe@2 = Utc_dt,
tempo:naive_datetime_get_time(_pipe@2)
end
)
div 1000000000).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 471).
-spec to_unix_milli_utc(tempo:date_time()) -> integer().
to_unix_milli_utc(Datetime) ->
Utc_dt = begin
_pipe = Datetime,
apply_offset(_pipe)
end,
tempo@date:to_unix_milli_utc(
begin
_pipe@1 = Utc_dt,
tempo:naive_datetime_get_date(_pipe@1)
end
)
+ (tempo@time:to_nanoseconds(
begin
_pipe@2 = Utc_dt,
tempo:naive_datetime_get_time(_pipe@2)
end
)
div 1000000).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 503).
-spec to_unix_micro_utc(tempo:date_time()) -> integer().
to_unix_micro_utc(Datetime) ->
Utc_dt = begin
_pipe = Datetime,
apply_offset(_pipe)
end,
tempo@date:to_unix_micro_utc(
begin
_pipe@1 = Utc_dt,
tempo:naive_datetime_get_date(_pipe@1)
end
)
+ (tempo@time:to_nanoseconds(
begin
_pipe@2 = Utc_dt,
tempo:naive_datetime_get_time(_pipe@2)
end
)
div 1000).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 761).
-spec to_utc(tempo:date_time()) -> tempo:date_time().
to_utc(Datetime) ->
_pipe = Datetime,
_pipe@1 = apply_offset(_pipe),
tempo@naive_datetime:set_offset(_pipe@1, {offset, 0}).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 1033).
-spec compare(tempo:date_time(), tempo:date_time()) -> gleam@order:order().
compare(A, B) ->
_pipe = apply_offset(A),
tempo@naive_datetime:compare(_pipe, apply_offset(B)).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 1056).
-spec is_earlier(tempo:date_time(), tempo:date_time()) -> boolean().
is_earlier(A, B) ->
compare(A, B) =:= lt.
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 1078).
-spec is_earlier_or_equal(tempo:date_time(), tempo:date_time()) -> boolean().
is_earlier_or_equal(A, B) ->
(compare(A, B) =:= lt) orelse (compare(A, B) =:= eq).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 1100).
-spec is_equal(tempo:date_time(), tempo:date_time()) -> boolean().
is_equal(A, B) ->
compare(A, B) =:= eq.
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 1123).
-spec is_later(tempo:date_time(), tempo:date_time()) -> boolean().
is_later(A, B) ->
compare(A, B) =:= gt.
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 1145).
-spec is_later_or_equal(tempo:date_time(), tempo:date_time()) -> boolean().
is_later_or_equal(A, B) ->
(compare(A, B) =:= gt) orelse (compare(A, B) =:= eq).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 1208).
-spec as_period(tempo:date_time(), tempo:date_time()) -> tempo:period().
as_period(Start, End) ->
{Start@1, End@1} = case begin
_pipe = Start,
is_earlier_or_equal(_pipe, End)
end of
true ->
{Start, End};
false ->
{End, Start}
end,
{period, Start@1, End@1}.
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 1150).
-spec difference_from(tempo:date_time(), tempo:date_time()) -> tempo:period().
difference_from(A, B) ->
as_period(B, A).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 1180).
-spec difference(tempo:date_time(), tempo:date_time()) -> tempo:period().
difference(A, B) ->
as_period(A, B).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 1248).
-spec subtract(tempo:date_time(), tempo:duration()) -> tempo:date_time().
subtract(Datetime, Duration_to_subtract) ->
_pipe = Datetime,
_pipe@1 = drop_offset(_pipe),
_pipe@2 = tempo@naive_datetime:subtract(_pipe@1, Duration_to_subtract),
tempo@naive_datetime:set_offset(
_pipe@2,
begin
_pipe@3 = Datetime,
tempo:datetime_get_offset(_pipe@3)
end
).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 776).
-spec to_offset(tempo:date_time(), tempo:offset()) -> tempo:date_time().
to_offset(Datetime, Offset) ->
_pipe = Datetime,
_pipe@1 = to_utc(_pipe),
_pipe@2 = subtract(_pipe@1, tempo@offset:to_duration(Offset)),
_pipe@3 = drop_offset(_pipe@2),
tempo@naive_datetime:set_offset(_pipe@3, Offset).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 815).
-spec to_local(tempo:date_time()) -> tempo:uncertain_conversion(tempo:date_time()).
to_local(Datetime) ->
gleam@bool:lazy_guard(
begin
_pipe = Datetime,
tempo:datetime_get_offset(_pipe)
end
=:= tempo@offset:local(),
fun() -> {precise, Datetime} end,
fun() ->
Local_dt = begin
_pipe@1 = Datetime,
to_offset(_pipe@1, tempo@offset:local())
end,
case begin
_pipe@2 = Local_dt,
_pipe@3 = tempo:datetime_get_naive(_pipe@2),
tempo:naive_datetime_get_date(_pipe@3)
end
=:= tempo@date:current_local() of
true ->
{precise, Local_dt};
false ->
{imprecise, Local_dt}
end
end
).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 123).
-spec now_local() -> tempo:date_time().
now_local() ->
case begin
_pipe = now_utc(),
to_local(_pipe)
end of
{precise, Datetime} ->
Datetime;
{imprecise, Datetime@1} ->
Datetime@1
end.
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 165).
-spec now_text() -> binary().
now_text() ->
_pipe = now_local(),
_pipe@1 = drop_offset(_pipe),
_pipe@2 = tempo@naive_datetime:to_milli_precision(_pipe@1),
_pipe@3 = tempo@naive_datetime:to_string(_pipe@2),
gleam@string:replace(_pipe@3, <<"T"/utf8>>, <<" "/utf8>>).
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 862).
-spec to_local_time(tempo:date_time()) -> tempo:uncertain_conversion(tempo:time()).
to_local_time(Datetime) ->
case to_local(Datetime) of
{precise, Datetime@1} ->
_pipe = Datetime@1,
_pipe@1 = tempo:datetime_get_naive(_pipe),
_pipe@2 = tempo:naive_datetime_get_time(_pipe@1),
{precise, _pipe@2};
{imprecise, Datetime@2} ->
_pipe@3 = Datetime@2,
_pipe@4 = tempo:datetime_get_naive(_pipe@3),
_pipe@5 = tempo:naive_datetime_get_time(_pipe@4),
{imprecise, _pipe@5}
end.
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 907).
-spec to_local_date(tempo:date_time()) -> tempo:uncertain_conversion(tempo:date()).
to_local_date(Datetime) ->
case to_local(Datetime) of
{precise, Datetime@1} ->
_pipe = Datetime@1,
_pipe@1 = tempo:datetime_get_naive(_pipe),
_pipe@2 = tempo:naive_datetime_get_date(_pipe@1),
{precise, _pipe@2};
{imprecise, Datetime@2} ->
_pipe@3 = Datetime@2,
_pipe@4 = tempo:datetime_get_naive(_pipe@3),
_pipe@5 = tempo:naive_datetime_get_date(_pipe@4),
{imprecise, _pipe@5}
end.
-file("/home/john/Repos/tempo/src/tempo/datetime.gleam", 1275).
-spec time_left_in_day(tempo:date_time()) -> tempo:time().
time_left_in_day(Datetime) ->
_pipe = Datetime,
_pipe@1 = tempo:datetime_get_naive(_pipe),
_pipe@2 = tempo:naive_datetime_get_time(_pipe@1),
tempo@time:left_in_day(_pipe@2).