Current section

Files

Jump to
gtempo src tempo@time.erl
Raw

src/tempo@time.erl

-module(tempo@time).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([new/3, new_milli/4, new_micro/4, new_nano/4, now_utc/0, now_local/0, now_monotonic/0, now_unique/0, test_literal/3, test_literal_milli/4, test_literal_micro/4, test_literal_nano/4, get_hour/1, get_minute/1, get_second/1, get_nanosecond/1, to_string/1, from_string/1, literal/1, parse/2, parse_any/1, replace_format/2, format/2, from_unix_utc/1, from_unix_milli_utc/1, from_unix_micro_utc/1, from_unix_nano_utc/1, to_tuple/1, from_tuple/1, to_tuple_nanosecond/1, from_tuple_nanosecond/1, to_duration/1, from_duration/1, compare/2, is_earlier/2, is_earlier_or_equal/2, is_equal/2, is_later/2, is_later_or_equal/2, is_between/3, is_outside/3, difference/2, difference_abs/2, add/2, adj/2, subtract/2, left_in_day/1, until/2, since/2]).
-export_type([boundary/0]).
-type boundary() :: {boundary, tempo:time(), boolean()}.
-file("/home/john/tempo/src/tempo/time.gleam", 67).
-spec new(integer(), integer(), integer()) -> {ok, tempo:time()} |
{error, tempo:time_out_of_bounds_error()}.
new(Hour, Minute, Second) ->
tempo:new_time(Hour, Minute, Second).
-file("/home/john/tempo/src/tempo/time.gleam", 93).
-spec new_milli(integer(), integer(), integer(), integer()) -> {ok,
tempo:time()} |
{error, tempo:time_out_of_bounds_error()}.
new_milli(Hour, Minute, Second, Millisecond) ->
tempo:new_time_milli(Hour, Minute, Second, Millisecond).
-file("/home/john/tempo/src/tempo/time.gleam", 120).
-spec new_micro(integer(), integer(), integer(), integer()) -> {ok,
tempo:time()} |
{error, tempo:time_out_of_bounds_error()}.
new_micro(Hour, Minute, Second, Microsecond) ->
tempo:new_time_micro(Hour, Minute, Second, Microsecond).
-file("/home/john/tempo/src/tempo/time.gleam", 147).
-spec new_nano(integer(), integer(), integer(), integer()) -> {ok, tempo:time()} |
{error, tempo:time_out_of_bounds_error()}.
new_nano(Hour, Minute, Second, Nanosecond) ->
tempo:new_time_nano(Hour, Minute, Second, Nanosecond).
-file("/home/john/tempo/src/tempo/time.gleam", 204).
-spec now_utc() -> tempo:time().
now_utc() ->
{Now_monotonic, Now_unique} = tempo:now_monounique(),
Now_ts_nano = tempo_ffi:now(),
Date_ts_nano = (tempo@date:to_unix_utc(
tempo@date:from_unix_utc(Now_ts_nano div 1000000000)
))
* 1000000000,
_pipe = tempo:time_from_nanoseconds(Now_ts_nano - Date_ts_nano),
tempo:time_set_mono(_pipe, {some, Now_monotonic}, {some, Now_unique}).
-file("/home/john/tempo/src/tempo/time.gleam", 233).
-spec now_local() -> tempo:time().
now_local() ->
{Now_monotonic, Now_unique} = tempo:now_monounique(),
Now_ts_nano = tempo_ffi:now(),
Date_ts_nano = (tempo@date:to_unix_utc(
tempo@date:from_unix_utc(Now_ts_nano div 1000000000)
))
* 1000000000,
_pipe = tempo:time_from_nanoseconds(
(Now_ts_nano - Date_ts_nano) + tempo@offset:local_nano()
),
tempo:time_set_mono(_pipe, {some, Now_monotonic}, {some, Now_unique}).
-file("/home/john/tempo/src/tempo/time.gleam", 258).
-spec now_monotonic() -> integer().
now_monotonic() ->
tempo_ffi:now_monotonic().
-file("/home/john/tempo/src/tempo/time.gleam", 276).
-spec now_unique() -> integer().
now_unique() ->
tempo_ffi:now_unique().
-file("/home/john/tempo/src/tempo/time.gleam", 329).
-spec validate(tempo:time()) -> {ok, tempo:time()} |
{error, tempo:time_out_of_bounds_error()}.
validate(Time) ->
tempo:validate_time(Time).
-file("/home/john/tempo/src/tempo/time.gleam", 284).
-spec test_literal(integer(), integer(), integer()) -> tempo:time().
test_literal(Hour, Minute, Second) ->
_assert_subject = begin
_pipe = tempo:time(Hour, Minute, Second, 0, none, none),
validate(_pipe)
end,
{ok, Time} = 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/time"/utf8>>,
function => <<"test_literal"/utf8>>,
line => 285})
end,
Time.
-file("/home/john/tempo/src/tempo/time.gleam", 291).
-spec test_literal_milli(integer(), integer(), integer(), integer()) -> tempo:time().
test_literal_milli(Hour, Minute, Second, Millisecond) ->
_assert_subject = begin
_pipe = tempo:time(
Hour,
Minute,
Second,
Millisecond * 1000000,
none,
none
),
validate(_pipe)
end,
{ok, Time} = 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/time"/utf8>>,
function => <<"test_literal_milli"/utf8>>,
line => 297})
end,
Time.
-file("/home/john/tempo/src/tempo/time.gleam", 304).
-spec test_literal_micro(integer(), integer(), integer(), integer()) -> tempo:time().
test_literal_micro(Hour, Minute, Second, Microsecond) ->
_assert_subject = begin
_pipe = tempo:time(Hour, Minute, Second, Microsecond * 1000, none, none),
validate(_pipe)
end,
{ok, Time} = 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/time"/utf8>>,
function => <<"test_literal_micro"/utf8>>,
line => 310})
end,
Time.
-file("/home/john/tempo/src/tempo/time.gleam", 317).
-spec test_literal_nano(integer(), integer(), integer(), integer()) -> tempo:time().
test_literal_nano(Hour, Minute, Second, Nanosecond) ->
_assert_subject = begin
_pipe = tempo:time(Hour, Minute, Second, Nanosecond, none, none),
validate(_pipe)
end,
{ok, Time} = 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/time"/utf8>>,
function => <<"test_literal_nano"/utf8>>,
line => 323})
end,
Time.
-file("/home/john/tempo/src/tempo/time.gleam", 342).
-spec get_hour(tempo:time()) -> integer().
get_hour(Time) ->
_pipe = Time,
tempo:time_get_hour(_pipe).
-file("/home/john/tempo/src/tempo/time.gleam", 355).
-spec get_minute(tempo:time()) -> integer().
get_minute(Time) ->
_pipe = Time,
tempo:time_get_minute(_pipe).
-file("/home/john/tempo/src/tempo/time.gleam", 368).
-spec get_second(tempo:time()) -> integer().
get_second(Time) ->
_pipe = Time,
tempo:time_get_second(_pipe).
-file("/home/john/tempo/src/tempo/time.gleam", 381).
-spec get_nanosecond(tempo:time()) -> integer().
get_nanosecond(Time) ->
_pipe = Time,
tempo:time_get_nano(_pipe).
-file("/home/john/tempo/src/tempo/time.gleam", 393).
-spec to_string(tempo:time()) -> binary().
to_string(Time) ->
_pipe@9 = gleam_stdlib:identity(
[begin
_pipe = Time,
_pipe@1 = tempo:time_get_hour(_pipe),
_pipe@2 = erlang:integer_to_binary(_pipe@1),
gleam@string:pad_start(_pipe@2, 2, <<"0"/utf8>>)
end,
<<":"/utf8>>,
begin
_pipe@3 = Time,
_pipe@4 = tempo:time_get_minute(_pipe@3),
_pipe@5 = erlang:integer_to_binary(_pipe@4),
gleam@string:pad_start(_pipe@5, 2, <<"0"/utf8>>)
end,
<<":"/utf8>>,
begin
_pipe@6 = Time,
_pipe@7 = tempo:time_get_second(_pipe@6),
_pipe@8 = erlang:integer_to_binary(_pipe@7),
gleam@string:pad_start(_pipe@8, 2, <<"0"/utf8>>)
end]
),
_pipe@10 = gleam@string_tree:append(_pipe@9, <<"."/utf8>>),
_pipe@13 = gleam@string_tree:append(
_pipe@10,
begin
_pipe@11 = (tempo:time_get_nano(Time) div 1000000),
_pipe@12 = erlang:integer_to_binary(_pipe@11),
gleam@string:pad_start(_pipe@12, 3, <<"0"/utf8>>)
end
),
unicode:characters_to_binary(_pipe@13).
-file("/home/john/tempo/src/tempo/time.gleam", 433).
-spec from_string(binary()) -> {ok, tempo:time()} |
{error, tempo:time_parse_error()}.
from_string(Time) ->
gleam@result:'try'(
begin
_pipe = case gleam@string:split(Time, <<":"/utf8>>) of
[Hour, Minute, Second] ->
{ok, {Hour, Minute, Second}};
[Hour@1, Minute@1] ->
{ok, {Hour@1, Minute@1, <<"0"/utf8>>}};
_ ->
{error, nil}
end,
gleam@result:try_recover(
_pipe,
fun(_) ->
case {string:length(Time),
gleam_stdlib:contains_string(Time, <<"."/utf8>>)} of
{6, false} ->
{ok,
{gleam@string:slice(Time, 0, 2),
gleam@string:slice(Time, 2, 2),
gleam@string:slice(Time, 4, 2)}};
{4, false} ->
{ok,
{gleam@string:slice(Time, 0, 2),
gleam@string:slice(Time, 2, 2),
<<"0"/utf8>>}};
{L, true} when L >= 7 ->
{ok,
{gleam@string:slice(Time, 0, 2),
gleam@string:slice(Time, 2, 2),
gleam@string:slice(Time, 4, 12)}};
{_, _} ->
{error, {time_invalid_format, Time}}
end
end
)
end,
fun(_use0) ->
{Hour@2, Minute@2, Second@1} = _use0,
gleam@result:'try'(
case {gleam_stdlib:parse_int(Hour@2),
gleam_stdlib:parse_int(Minute@2),
gleam@string:split(Second@1, <<"."/utf8>>)} of
{{ok, Hour@3}, {ok, Minute@3}, [Second@2, Second_fraction]} ->
Second_fraction_length = string:length(Second_fraction),
case Second_fraction_length of
Len when Len =< 3 ->
case {gleam_stdlib:parse_int(Second@2),
gleam_stdlib:parse_int(
begin
_pipe@1 = Second_fraction,
gleam@string:pad_end(
_pipe@1,
3,
<<"0"/utf8>>
)
end
)} of
{{ok, Second@3}, {ok, Milli}} ->
{ok,
tempo:time(
Hour@3,
Minute@3,
Second@3,
Milli * 1000000,
none,
none
)};
{_, _} ->
{error,
{time_invalid_format,
<<"Non-integer second or millisecond value"/utf8>>}}
end;
Len@1 when Len@1 =< 6 ->
case {gleam_stdlib:parse_int(Second@2),
gleam_stdlib:parse_int(
begin
_pipe@2 = Second_fraction,
gleam@string:pad_end(
_pipe@2,
6,
<<"0"/utf8>>
)
end
)} of
{{ok, Second@4}, {ok, Micro}} ->
{ok,
tempo:time(
Hour@3,
Minute@3,
Second@4,
Micro * 1000,
none,
none
)};
{_, _} ->
{error,
{time_invalid_format,
<<"Non-integer second or microsecond value"/utf8>>}}
end;
Len@2 when Len@2 =< 9 ->
case {gleam_stdlib:parse_int(Second@2),
gleam_stdlib:parse_int(
begin
_pipe@3 = Second_fraction,
gleam@string:pad_end(
_pipe@3,
9,
<<"0"/utf8>>
)
end
)} of
{{ok, Second@5}, {ok, Nano}} ->
{ok,
tempo:time(
Hour@3,
Minute@3,
Second@5,
Nano,
none,
none
)};
{_, _} ->
{error,
{time_invalid_format,
<<"Non-integer second or nanosecond value"/utf8>>}}
end;
_ ->
{error,
{time_invalid_format,
<<"Invalid subsecond value"/utf8>>}}
end;
{{ok, Hour@4}, {ok, Minute@4}, _} ->
case gleam_stdlib:parse_int(Second@1) of
{ok, Second@6} ->
{ok,
tempo:time(
Hour@4,
Minute@4,
Second@6,
0,
none,
none
)};
_ ->
{error,
{time_invalid_format,
<<"Non-integer second value"/utf8>>}}
end;
{_, _, _} ->
{error,
{time_invalid_format,
<<"Non-integer hour or minute value"/utf8>>}}
end,
fun(Time@1) -> _pipe@4 = validate(Time@1),
gleam@result:map_error(
_pipe@4,
fun(E) -> {time_out_of_bounds, E} end
) end
)
end
).
-file("/home/john/tempo/src/tempo/time.gleam", 174).
-spec literal(binary()) -> tempo:time().
literal(Time) ->
case from_string(Time) of
{ok, Time@1} ->
Time@1;
{error, {time_invalid_format, _}} ->
erlang:error(#{gleam_error => panic,
message => <<"Invalid time literal format"/utf8>>,
module => <<"tempo/time"/utf8>>,
function => <<"literal"/utf8>>,
line => 177});
{error, {time_out_of_bounds, time_hour_out_of_bounds}} ->
erlang:error(#{gleam_error => panic,
message => <<"Invalid time literal hour value"/utf8>>,
module => <<"tempo/time"/utf8>>,
function => <<"literal"/utf8>>,
line => 179});
{error, {time_out_of_bounds, time_minute_out_of_bounds}} ->
erlang:error(#{gleam_error => panic,
message => <<"Invalid time literal minute value"/utf8>>,
module => <<"tempo/time"/utf8>>,
function => <<"literal"/utf8>>,
line => 181});
{error, {time_out_of_bounds, time_second_out_of_bounds}} ->
erlang:error(#{gleam_error => panic,
message => <<"Invalid time literal second value"/utf8>>,
module => <<"tempo/time"/utf8>>,
function => <<"literal"/utf8>>,
line => 183});
{error, {time_out_of_bounds, time_nano_second_out_of_bounds}} ->
erlang:error(#{gleam_error => panic,
message => <<"Invalid time literal nanosecond value"/utf8>>,
module => <<"tempo/time"/utf8>>,
function => <<"literal"/utf8>>,
line => 185})
end.
-file("/home/john/tempo/src/tempo/time.gleam", 555).
-spec parse(binary(), binary()) -> {ok, tempo:time()} |
{error, tempo:time_parse_error()}.
parse(Str, Fmt) ->
gleam@result:'try'(
begin
_pipe = tempo:consume_format(Str, Fmt),
gleam@result:map_error(
_pipe,
fun(Msg) -> {time_invalid_format, Msg} end
)
end,
fun(_use0) ->
{Parts, _} = _use0,
tempo:find_time(Parts)
end
).
-file("/home/john/tempo/src/tempo/time.gleam", 582).
-spec parse_any(binary()) -> {ok, tempo:time()} | {error, nil}.
parse_any(Str) ->
case tempo:parse_any(Str) of
{_, {some, Time}, _} ->
{ok, Time};
{_, none, _} ->
{error, nil}
end.
-file("/home/john/tempo/src/tempo/time.gleam", 641).
-spec replace_format(binary(), tempo:time()) -> binary().
replace_format(Content, Time) ->
case Content of
<<"H"/utf8>> ->
_pipe = Time,
_pipe@1 = get_hour(_pipe),
erlang:integer_to_binary(_pipe@1);
<<"HH"/utf8>> ->
_pipe@2 = Time,
_pipe@3 = get_hour(_pipe@2),
_pipe@4 = erlang:integer_to_binary(_pipe@3),
gleam@string:pad_start(_pipe@4, 2, <<"0"/utf8>>);
<<"h"/utf8>> ->
_pipe@5 = Time,
_pipe@6 = get_hour(_pipe@5),
_pipe@7 = (fun(Hour) -> case Hour of
_ when Hour =:= 0 ->
12;
_ when Hour > 12 ->
Hour - 12;
_ ->
Hour
end end)(_pipe@6),
erlang:integer_to_binary(_pipe@7);
<<"hh"/utf8>> ->
_pipe@8 = Time,
_pipe@9 = get_hour(_pipe@8),
_pipe@10 = (fun(Hour@1) -> case Hour@1 of
_ when Hour@1 =:= 0 ->
12;
_ when Hour@1 > 12 ->
Hour@1 - 12;
_ ->
Hour@1
end end)(_pipe@9),
_pipe@11 = erlang:integer_to_binary(_pipe@10),
gleam@string:pad_start(_pipe@11, 2, <<"0"/utf8>>);
<<"a"/utf8>> ->
_pipe@12 = Time,
_pipe@13 = get_hour(_pipe@12),
(fun(Hour@2) -> case Hour@2 >= 12 of
true ->
<<"pm"/utf8>>;
false ->
<<"am"/utf8>>
end end)(_pipe@13);
<<"A"/utf8>> ->
_pipe@14 = Time,
_pipe@15 = get_hour(_pipe@14),
(fun(Hour@3) -> case Hour@3 >= 12 of
true ->
<<"PM"/utf8>>;
false ->
<<"AM"/utf8>>
end end)(_pipe@15);
<<"m"/utf8>> ->
_pipe@16 = Time,
_pipe@17 = get_minute(_pipe@16),
erlang:integer_to_binary(_pipe@17);
<<"mm"/utf8>> ->
_pipe@18 = Time,
_pipe@19 = get_minute(_pipe@18),
_pipe@20 = erlang:integer_to_binary(_pipe@19),
gleam@string:pad_start(_pipe@20, 2, <<"0"/utf8>>);
<<"s"/utf8>> ->
_pipe@21 = Time,
_pipe@22 = get_second(_pipe@21),
erlang:integer_to_binary(_pipe@22);
<<"ss"/utf8>> ->
_pipe@23 = Time,
_pipe@24 = get_second(_pipe@23),
_pipe@25 = erlang:integer_to_binary(_pipe@24),
gleam@string:pad_start(_pipe@25, 2, <<"0"/utf8>>);
<<"SSS"/utf8>> ->
_pipe@26 = Time,
_pipe@27 = get_nanosecond(_pipe@26),
_pipe@28 = (fun(Nano) -> Nano div 1000000 end)(_pipe@27),
_pipe@29 = erlang:integer_to_binary(_pipe@28),
gleam@string:pad_start(_pipe@29, 3, <<"0"/utf8>>);
<<"SSSS"/utf8>> ->
_pipe@30 = Time,
_pipe@31 = get_nanosecond(_pipe@30),
_pipe@32 = (fun(Nano@1) -> Nano@1 div 1000 end)(_pipe@31),
_pipe@33 = erlang:integer_to_binary(_pipe@32),
gleam@string:pad_start(_pipe@33, 6, <<"0"/utf8>>);
<<"SSSSS"/utf8>> ->
_pipe@34 = Time,
_pipe@35 = get_nanosecond(_pipe@34),
_pipe@36 = erlang:integer_to_binary(_pipe@35),
gleam@string:pad_start(_pipe@36, 9, <<"0"/utf8>>);
_ ->
Content
end.
-file("/home/john/tempo/src/tempo/time.gleam", 619).
-spec format(tempo:time(), binary()) -> binary().
format(Time, Fmt) ->
_assert_subject = gleam@regexp: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/time"/utf8>>,
function => <<"format"/utf8>>,
line => 620})
end,
_pipe = gleam@regexp:scan(Re, Fmt),
_pipe@1 = lists:reverse(_pipe),
_pipe@2 = gleam@list:fold(_pipe@1, [], fun(Acc, Match) -> case Match of
{match, Content, []} ->
[replace_format(Content, Time) | Acc];
{match, _, [{some, Sub}]} ->
[Sub | Acc];
{match, Content@1, _} ->
[Content@1 | Acc]
end end),
gleam@string:join(_pipe@2, <<""/utf8>>).
-file("/home/john/tempo/src/tempo/time.gleam", 738).
-spec from_unix_utc(integer()) -> tempo:time().
from_unix_utc(Unix_ts) ->
_pipe = (Unix_ts - (tempo@date:to_unix_utc(
tempo@date:from_unix_utc(Unix_ts)
)))
* 1000000000,
tempo:time_from_nanoseconds(_pipe).
-file("/home/john/tempo/src/tempo/time.gleam", 760).
-spec from_unix_milli_utc(integer()) -> tempo:time().
from_unix_milli_utc(Unix_ts) ->
_pipe = (Unix_ts - (tempo@date:to_unix_milli_utc(
tempo@date:from_unix_milli_utc(Unix_ts)
)))
* 1000000,
tempo:time_from_nanoseconds(_pipe).
-file("/home/john/tempo/src/tempo/time.gleam", 782).
-spec from_unix_micro_utc(integer()) -> tempo:time().
from_unix_micro_utc(Unix_ts) ->
_pipe = (Unix_ts - (tempo@date:to_unix_micro_utc(
tempo@date:from_unix_micro_utc(Unix_ts)
)))
* 1000,
tempo:time_from_nanoseconds(_pipe).
-file("/home/john/tempo/src/tempo/time.gleam", 804).
-spec from_unix_nano_utc(integer()) -> tempo:time().
from_unix_nano_utc(Unix_ts) ->
_pipe = (Unix_ts - ((tempo@date:to_unix_micro_utc(
tempo@date:from_unix_micro_utc(Unix_ts div 1000)
))
* 1000)),
tempo:time_from_nanoseconds(_pipe).
-file("/home/john/tempo/src/tempo/time.gleam", 824).
-spec to_tuple(tempo:time()) -> {integer(), integer(), integer()}.
to_tuple(Time) ->
{begin
_pipe = Time,
tempo:time_get_hour(_pipe)
end,
begin
_pipe@1 = Time,
tempo:time_get_minute(_pipe@1)
end,
begin
_pipe@2 = Time,
tempo:time_get_second(_pipe@2)
end}.
-file("/home/john/tempo/src/tempo/time.gleam", 842).
-spec from_tuple({integer(), integer(), integer()}) -> {ok, tempo:time()} |
{error, tempo:time_out_of_bounds_error()}.
from_tuple(Time) ->
new(
erlang:element(1, Time),
erlang:element(2, Time),
erlang:element(3, Time)
).
-file("/home/john/tempo/src/tempo/time.gleam", 858).
-spec to_tuple_nanosecond(tempo:time()) -> {integer(),
integer(),
integer(),
integer()}.
to_tuple_nanosecond(Time) ->
{begin
_pipe = Time,
tempo:time_get_hour(_pipe)
end,
begin
_pipe@1 = Time,
tempo:time_get_minute(_pipe@1)
end,
begin
_pipe@2 = Time,
tempo:time_get_second(_pipe@2)
end,
begin
_pipe@3 = Time,
tempo:time_get_nano(_pipe@3)
end}.
-file("/home/john/tempo/src/tempo/time.gleam", 878).
-spec from_tuple_nanosecond({integer(), integer(), integer(), integer()}) -> {ok,
tempo:time()} |
{error, tempo:time_out_of_bounds_error()}.
from_tuple_nanosecond(Time) ->
new_nano(
erlang:element(1, Time),
erlang:element(2, Time),
erlang:element(3, Time),
erlang:element(4, Time)
).
-file("/home/john/tempo/src/tempo/time.gleam", 901).
-spec to_duration(tempo:time()) -> tempo:duration().
to_duration(Time) ->
tempo:time_to_duration(Time).
-file("/home/john/tempo/src/tempo/time.gleam", 939).
-spec from_duration(tempo:duration()) -> tempo:time().
from_duration(Duration) ->
_pipe = Duration,
_pipe@1 = tempo:duration_get_ns(_pipe),
tempo:time_from_nanoseconds(_pipe@1).
-file("/home/john/tempo/src/tempo/time.gleam", 964).
-spec compare(tempo:time(), tempo:time()) -> gleam@order:order().
compare(A, B) ->
case {tempo:time_get_unique(A), tempo:time_get_unique(B)} of
{{some, Au}, {some, Bu}} ->
gleam@int:compare(Au, Bu);
{_, _} ->
case {tempo:time_get_mono(A), tempo:time_get_mono(B)} of
{{some, Amns}, {some, Bmns}} ->
gleam@int:compare(Amns, Bmns);
{_, _} ->
case begin
_pipe = A,
tempo:time_get_hour(_pipe)
end
=:= begin
_pipe@1 = B,
tempo:time_get_hour(_pipe@1)
end of
true ->
case begin
_pipe@2 = A,
tempo:time_get_minute(_pipe@2)
end
=:= begin
_pipe@3 = B,
tempo:time_get_minute(_pipe@3)
end of
true ->
case begin
_pipe@4 = A,
tempo:time_get_second(_pipe@4)
end
=:= begin
_pipe@5 = B,
tempo:time_get_second(_pipe@5)
end of
true ->
case begin
_pipe@6 = A,
tempo:time_get_nano(_pipe@6)
end
=:= begin
_pipe@7 = B,
tempo:time_get_nano(_pipe@7)
end of
true ->
eq;
false ->
case begin
_pipe@8 = A,
tempo:time_get_nano(
_pipe@8
)
end
< begin
_pipe@9 = B,
tempo:time_get_nano(
_pipe@9
)
end of
true ->
lt;
false ->
gt
end
end;
false ->
case begin
_pipe@10 = A,
tempo:time_get_second(_pipe@10)
end
< begin
_pipe@11 = B,
tempo:time_get_second(_pipe@11)
end of
true ->
lt;
false ->
gt
end
end;
false ->
case begin
_pipe@12 = A,
tempo:time_get_minute(_pipe@12)
end
< begin
_pipe@13 = B,
tempo:time_get_minute(_pipe@13)
end of
true ->
lt;
false ->
gt
end
end;
false ->
case begin
_pipe@14 = A,
tempo:time_get_hour(_pipe@14)
end
< begin
_pipe@15 = B,
tempo:time_get_hour(_pipe@15)
end of
true ->
lt;
false ->
gt
end
end
end
end.
-file("/home/john/tempo/src/tempo/time.gleam", 1036).
-spec is_earlier(tempo:time(), tempo:time()) -> boolean().
is_earlier(A, B) ->
compare(A, B) =:= lt.
-file("/home/john/tempo/src/tempo/time.gleam", 1060).
-spec is_earlier_or_equal(tempo:time(), tempo:time()) -> boolean().
is_earlier_or_equal(A, B) ->
(compare(A, B) =:= lt) orelse (compare(A, B) =:= eq).
-file("/home/john/tempo/src/tempo/time.gleam", 1079).
-spec is_equal(tempo:time(), tempo:time()) -> boolean().
is_equal(A, B) ->
compare(A, B) =:= eq.
-file("/home/john/tempo/src/tempo/time.gleam", 1104).
-spec is_later(tempo:time(), tempo:time()) -> boolean().
is_later(A, B) ->
compare(A, B) =:= gt.
-file("/home/john/tempo/src/tempo/time.gleam", 1128).
-spec is_later_or_equal(tempo:time(), tempo:time()) -> boolean().
is_later_or_equal(A, B) ->
(compare(A, B) =:= gt) orelse (compare(A, B) =:= eq).
-file("/home/john/tempo/src/tempo/time.gleam", 1148).
-spec is_between(tempo:time(), boundary(), boundary()) -> boolean().
is_between(Time, Start, End) ->
case erlang:element(3, Start) of
true ->
is_later_or_equal(Time, erlang:element(2, Start));
false ->
is_later(Time, erlang:element(2, Start))
end andalso case erlang:element(3, End) of
true ->
is_earlier_or_equal(Time, erlang:element(2, End));
false ->
is_earlier(Time, erlang:element(2, End))
end.
-file("/home/john/tempo/src/tempo/time.gleam", 1171).
-spec is_outside(tempo:time(), boundary(), boundary()) -> boolean().
is_outside(Time, Start, End) ->
case erlang:element(3, Start) of
true ->
is_earlier_or_equal(Time, erlang:element(2, Start));
false ->
is_earlier(Time, erlang:element(2, Start))
end orelse case erlang:element(3, End) of
true ->
is_later_or_equal(Time, erlang:element(2, End));
false ->
is_later(Time, erlang:element(2, End))
end.
-file("/home/john/tempo/src/tempo/time.gleam", 1201).
-spec difference(tempo:time(), tempo:time()) -> tempo:duration().
difference(A, B) ->
tempo:time_difference(A, B).
-file("/home/john/tempo/src/tempo/time.gleam", 1222).
-spec difference_abs(tempo:time(), tempo:time()) -> tempo:duration().
difference_abs(A, B) ->
Diff = case {tempo:time_get_mono(A), tempo:time_get_mono(B)} of
{{some, A_mns}, {some, B_mns}} ->
A_mns - B_mns;
{_, _} ->
tempo:time_to_nanoseconds(A) - tempo:time_to_nanoseconds(B)
end,
case Diff of
_ when Diff < 0 ->
_pipe = - Diff,
tempo:duration(_pipe);
_ ->
_pipe@1 = Diff,
tempo:duration(_pipe@1)
end.
-file("/home/john/tempo/src/tempo/time.gleam", 1256).
-spec add(tempo:time(), tempo:duration()) -> tempo:time().
add(A, B) ->
tempo:time_add(A, B).
-file("/home/john/tempo/src/tempo/time.gleam", 1238).
-spec adj(tempo:time(), tempo:duration()) -> tempo:time().
adj(A, B) ->
Added = add(A, B),
tempo:time_set_mono(
Added,
tempo:time_get_mono(Added),
tempo:time_get_unique(A)
).
-file("/home/john/tempo/src/tempo/time.gleam", 1269).
-spec subtract(tempo:time(), tempo:duration()) -> tempo:time().
subtract(A, B) ->
tempo:time_subtract(A, B).
-file("/home/john/tempo/src/tempo/time.gleam", 1286).
-spec left_in_day(tempo:time()) -> tempo:time().
left_in_day(Time) ->
_pipe@1 = 86400000000000 - begin
_pipe = Time,
tempo:time_to_nanoseconds(_pipe)
end,
tempo:time_from_nanoseconds(_pipe@1).
-file("/home/john/tempo/src/tempo/time.gleam", 1308).
-spec until(tempo:time(), tempo:time()) -> tempo:duration().
until(Time, Until) ->
Dur = begin
_pipe = Time,
_pipe@1 = difference(Until, _pipe),
tempo@duration:inverse(_pipe@1)
end,
case begin
_pipe@2 = Dur,
tempo@duration:is_negative(_pipe@2)
end of
true ->
tempo@duration:nanoseconds(0);
false ->
Dur
end.
-file("/home/john/tempo/src/tempo/time.gleam", 1334).
-spec since(tempo:time(), tempo:time()) -> tempo:duration().
since(Time, Since) ->
Dur = begin
_pipe = Time,
difference(Since, _pipe)
end,
case begin
_pipe@1 = Dur,
tempo@duration:is_negative(_pipe@1)
end of
true ->
tempo@duration:nanoseconds(0);
false ->
Dur
end.