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_monotonic/0, now_unique/0, test_literal/3, test_literal_milli/4, test_literal_micro/4, test_literal_nano/4, set_hour/2, set_minute/2, set_second/2, set_milli/2, set_micro/2, set_nano/2, get_hour/1, get_minute/1, get_second/1, get_nanosecond/1, to_second_precision/1, to_milli_precision/1, to_micro_precision/1, to_nano_precision/1, to_string/1, from_string/1, literal/1, parse/2, parse_any/1, replace_format/2, format/2, to_tuple/1, from_tuple/1, to_tuple_nanosecond/1, from_tuple_nanosecond/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, to_nanoseconds/1, to_duration/1, difference/2, difference_abs/2, from_nanoseconds/1, now_utc/0, now_local/0, from_unix_utc/1, from_unix_milli_utc/1, from_unix_micro_utc/1, from_unix_nano_utc/1, from_duration/1, add/2, subtract/2, left_in_day/1, until/2, since/2]).
-export_type([boundary/0]).
-type boundary() :: {boundary, tempo:time(), boolean()}.
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 67).
-spec new(integer(), integer(), integer()) -> {ok, tempo:time()} |
{error, tempo:error()}.
new(Hour, Minute, Second) ->
tempo:new_time(Hour, Minute, Second).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 93).
-spec new_milli(integer(), integer(), integer(), integer()) -> {ok,
tempo:time()} |
{error, tempo:error()}.
new_milli(Hour, Minute, Second, Millisecond) ->
tempo:new_time_milli(Hour, Minute, Second, Millisecond).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 120).
-spec new_micro(integer(), integer(), integer(), integer()) -> {ok,
tempo:time()} |
{error, tempo:error()}.
new_micro(Hour, Minute, Second, Microsecond) ->
tempo:new_time_micro(Hour, Minute, Second, Microsecond).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 147).
-spec new_nano(integer(), integer(), integer(), integer()) -> {ok, tempo:time()} |
{error, tempo:error()}.
new_nano(Hour, Minute, Second, Nanosecond) ->
tempo:new_time_nano(Hour, Minute, Second, Nanosecond).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 250).
-spec now_monotonic() -> integer().
now_monotonic() ->
tempo_ffi:now_monotonic().
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 268).
-spec now_unique() -> integer().
now_unique() ->
tempo_ffi:now_unique().
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 320).
-spec validate(tempo:time()) -> {ok, tempo:time()} | {error, tempo:error()}.
validate(Time) ->
tempo:validate_time(Time).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 276).
-spec test_literal(integer(), integer(), integer()) -> tempo:time().
test_literal(Hour, Minute, Second) ->
_assert_subject = begin
_pipe = tempo:time(Hour, Minute, Second, 0, sec, 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 => 277})
end,
Time.
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 283).
-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,
milli,
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 => 289})
end,
Time.
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 296).
-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,
micro,
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 => 302})
end,
Time.
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 309).
-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, nano, 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 => 315})
end,
Time.
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 327).
-spec set_hour(tempo:time(), integer()) -> {ok, tempo:time()} |
{error, tempo:error()}.
set_hour(Time, Hour) ->
case begin
_pipe = Time,
tempo:time_get_prec(_pipe)
end of
sec ->
new(
Hour,
begin
_pipe@1 = Time,
tempo:time_get_minute(_pipe@1)
end,
begin
_pipe@2 = Time,
tempo:time_get_second(_pipe@2)
end
);
milli ->
new_milli(
Hour,
begin
_pipe@3 = Time,
tempo:time_get_minute(_pipe@3)
end,
begin
_pipe@4 = Time,
tempo:time_get_second(_pipe@4)
end,
begin
_pipe@5 = Time,
tempo:time_get_nano(_pipe@5)
end
);
micro ->
new_micro(
Hour,
begin
_pipe@6 = Time,
tempo:time_get_minute(_pipe@6)
end,
begin
_pipe@7 = Time,
tempo:time_get_second(_pipe@7)
end,
begin
_pipe@8 = Time,
tempo:time_get_nano(_pipe@8)
end
);
nano ->
new_nano(
Hour,
begin
_pipe@9 = Time,
tempo:time_get_minute(_pipe@9)
end,
begin
_pipe@10 = Time,
tempo:time_get_second(_pipe@10)
end,
begin
_pipe@11 = Time,
tempo:time_get_nano(_pipe@11)
end
)
end.
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 358).
-spec set_minute(tempo:time(), integer()) -> {ok, tempo:time()} |
{error, tempo:error()}.
set_minute(Time, Minute) ->
case begin
_pipe = Time,
tempo:time_get_prec(_pipe)
end of
sec ->
new(
begin
_pipe@1 = Time,
tempo:time_get_hour(_pipe@1)
end,
Minute,
begin
_pipe@2 = Time,
tempo:time_get_second(_pipe@2)
end
);
milli ->
new_milli(
begin
_pipe@3 = Time,
tempo:time_get_hour(_pipe@3)
end,
Minute,
begin
_pipe@4 = Time,
tempo:time_get_second(_pipe@4)
end,
begin
_pipe@5 = Time,
tempo:time_get_nano(_pipe@5)
end
);
micro ->
new_micro(
begin
_pipe@6 = Time,
tempo:time_get_hour(_pipe@6)
end,
Minute,
begin
_pipe@7 = Time,
tempo:time_get_second(_pipe@7)
end,
begin
_pipe@8 = Time,
tempo:time_get_nano(_pipe@8)
end
);
nano ->
new_nano(
begin
_pipe@9 = Time,
tempo:time_get_hour(_pipe@9)
end,
Minute,
begin
_pipe@10 = Time,
tempo:time_get_second(_pipe@10)
end,
begin
_pipe@11 = Time,
tempo:time_get_nano(_pipe@11)
end
)
end.
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 392).
-spec set_second(tempo:time(), integer()) -> {ok, tempo:time()} |
{error, tempo:error()}.
set_second(Time, Second) ->
case begin
_pipe = Time,
tempo:time_get_prec(_pipe)
end of
sec ->
new(
begin
_pipe@1 = Time,
tempo:time_get_hour(_pipe@1)
end,
begin
_pipe@2 = Time,
tempo:time_get_minute(_pipe@2)
end,
Second
);
milli ->
new_milli(
begin
_pipe@3 = Time,
tempo:time_get_hour(_pipe@3)
end,
begin
_pipe@4 = Time,
tempo:time_get_minute(_pipe@4)
end,
Second,
begin
_pipe@5 = Time,
tempo:time_get_nano(_pipe@5)
end
);
micro ->
new_micro(
begin
_pipe@6 = Time,
tempo:time_get_hour(_pipe@6)
end,
begin
_pipe@7 = Time,
tempo:time_get_minute(_pipe@7)
end,
Second,
begin
_pipe@8 = Time,
tempo:time_get_nano(_pipe@8)
end
);
nano ->
new_nano(
begin
_pipe@9 = Time,
tempo:time_get_hour(_pipe@9)
end,
begin
_pipe@10 = Time,
tempo:time_get_minute(_pipe@10)
end,
Second,
begin
_pipe@11 = Time,
tempo:time_get_nano(_pipe@11)
end
)
end.
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 426).
-spec set_milli(tempo:time(), integer()) -> {ok, tempo:time()} |
{error, tempo:error()}.
set_milli(Time, Millisecond) ->
new_milli(
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,
Millisecond
).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 441).
-spec set_micro(tempo:time(), integer()) -> {ok, tempo:time()} |
{error, tempo:error()}.
set_micro(Time, Microsecond) ->
new_micro(
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,
Microsecond
).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 456).
-spec set_nano(tempo:time(), integer()) -> {ok, tempo:time()} |
{error, tempo:error()}.
set_nano(Time, Nanosecond) ->
new_nano(
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,
Nanosecond
).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 477).
-spec get_hour(tempo:time()) -> integer().
get_hour(Time) ->
_pipe = Time,
tempo:time_get_hour(_pipe).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 490).
-spec get_minute(tempo:time()) -> integer().
get_minute(Time) ->
_pipe = Time,
tempo:time_get_minute(_pipe).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 503).
-spec get_second(tempo:time()) -> integer().
get_second(Time) ->
_pipe = Time,
tempo:time_get_second(_pipe).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 516).
-spec get_nanosecond(tempo:time()) -> integer().
get_nanosecond(Time) ->
_pipe = Time,
tempo:time_get_nano(_pipe).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 531).
-spec to_second_precision(tempo:time()) -> tempo:time().
to_second_precision(Time) ->
tempo: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,
0,
sec,
begin
_pipe@3 = Time,
tempo:time_get_mono(_pipe@3)
end
).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 554).
-spec to_milli_precision(tempo:time()) -> tempo:time().
to_milli_precision(Time) ->
tempo: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,
(tempo:time_get_nano(Time) div 1000000) * 1000000,
milli,
begin
_pipe@3 = Time,
tempo:time_get_mono(_pipe@3)
end
).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 577).
-spec to_micro_precision(tempo:time()) -> tempo:time().
to_micro_precision(Time) ->
tempo: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,
(tempo:time_get_nano(Time) div 1000) * 1000,
micro,
begin
_pipe@3 = Time,
tempo:time_get_mono(_pipe@3)
end
).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 600).
-spec to_nano_precision(tempo:time()) -> tempo:time().
to_nano_precision(Time) ->
tempo: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,
nano,
begin
_pipe@4 = Time,
tempo:time_get_mono(_pipe@4)
end
).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 620).
-spec to_string(tempo:time()) -> binary().
to_string(Time) ->
Sb = gleam@string_builder:from_strings(
[begin
_pipe = Time,
_pipe@1 = tempo:time_get_hour(_pipe),
_pipe@2 = gleam@int:to_string(_pipe@1),
gleam@string:pad_left(_pipe@2, 2, <<"0"/utf8>>)
end,
<<":"/utf8>>,
begin
_pipe@3 = Time,
_pipe@4 = tempo:time_get_minute(_pipe@3),
_pipe@5 = gleam@int:to_string(_pipe@4),
gleam@string:pad_left(_pipe@5, 2, <<"0"/utf8>>)
end,
<<":"/utf8>>,
begin
_pipe@6 = Time,
_pipe@7 = tempo:time_get_second(_pipe@6),
_pipe@8 = gleam@int:to_string(_pipe@7),
gleam@string:pad_left(_pipe@8, 2, <<"0"/utf8>>)
end]
),
_pipe@19 = case begin
_pipe@9 = Time,
tempo:time_get_prec(_pipe@9)
end of
sec ->
Sb;
milli ->
_pipe@10 = gleam@string_builder:append(Sb, <<"."/utf8>>),
gleam@string_builder:append(
_pipe@10,
begin
_pipe@11 = (tempo:time_get_nano(Time) div 1000000),
_pipe@12 = gleam@int:to_string(_pipe@11),
gleam@string:pad_left(_pipe@12, 3, <<"0"/utf8>>)
end
);
micro ->
_pipe@13 = gleam@string_builder:append(Sb, <<"."/utf8>>),
gleam@string_builder:append(
_pipe@13,
begin
_pipe@14 = (tempo:time_get_nano(Time) div 1000),
_pipe@15 = gleam@int:to_string(_pipe@14),
gleam@string:pad_left(_pipe@15, 6, <<"0"/utf8>>)
end
);
nano ->
_pipe@16 = gleam@string_builder:append(Sb, <<"."/utf8>>),
gleam@string_builder:append(
_pipe@16,
begin
_pipe@17 = tempo:time_get_nano(Time),
_pipe@18 = gleam@int:to_string(_pipe@17),
gleam@string:pad_left(_pipe@18, 9, <<"0"/utf8>>)
end
)
end,
gleam@string_builder:to_string(_pipe@19).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 680).
-spec from_string(binary()) -> {ok, tempo:time()} | {error, tempo: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, time_invalid_format}
end,
gleam@result:try_recover(
_pipe,
fun(_) ->
case {gleam@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}
end
end
)
end,
fun(_use0) ->
{Hour@2, Minute@2, Second@1} = _use0,
_pipe@4 = case {gleam@int:parse(Hour@2),
gleam@int:parse(Minute@2),
gleam@string:split(Second@1, <<"."/utf8>>)} of
{{ok, Hour@3}, {ok, Minute@3}, [Second@2, Second_fraction]} ->
Second_fraction_length = gleam@string:length(
Second_fraction
),
case Second_fraction_length of
Len when Len =< 3 ->
case {gleam@int:parse(Second@2),
gleam@int:parse(
begin
_pipe@1 = Second_fraction,
gleam@string:pad_right(
_pipe@1,
3,
<<"0"/utf8>>
)
end
)} of
{{ok, Second@3}, {ok, Milli}} ->
{ok,
tempo:time(
Hour@3,
Minute@3,
Second@3,
Milli * 1000000,
milli,
none
)};
{_, _} ->
{error, time_invalid_format}
end;
Len@1 when Len@1 =< 6 ->
case {gleam@int:parse(Second@2),
gleam@int:parse(
begin
_pipe@2 = Second_fraction,
gleam@string:pad_right(
_pipe@2,
6,
<<"0"/utf8>>
)
end
)} of
{{ok, Second@4}, {ok, Micro}} ->
{ok,
tempo:time(
Hour@3,
Minute@3,
Second@4,
Micro * 1000,
micro,
none
)};
{_, _} ->
{error, time_invalid_format}
end;
Len@2 when Len@2 =< 9 ->
case {gleam@int:parse(Second@2),
gleam@int:parse(
begin
_pipe@3 = Second_fraction,
gleam@string:pad_right(
_pipe@3,
9,
<<"0"/utf8>>
)
end
)} of
{{ok, Second@5}, {ok, Nano}} ->
{ok,
tempo:time(
Hour@3,
Minute@3,
Second@5,
Nano,
nano,
none
)};
{_, _} ->
{error, time_invalid_format}
end;
_ ->
{error, time_invalid_format}
end;
{{ok, Hour@4}, {ok, Minute@4}, _} ->
case gleam@int:parse(Second@1) of
{ok, Second@6} ->
{ok,
tempo:time(
Hour@4,
Minute@4,
Second@6,
0,
sec,
none
)};
_ ->
{error, time_invalid_format}
end;
{_, _, _} ->
{error, time_invalid_format}
end,
gleam@result:'try'(_pipe@4, fun validate/1)
end
).
-file("/home/john/Repos/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} ->
erlang:error(#{gleam_error => panic,
message => <<"Invalid time literal value"/utf8>>,
module => <<"tempo/time"/utf8>>,
function => <<"literal"/utf8>>,
line => 178});
{error, _} ->
erlang:error(#{gleam_error => panic,
message => <<"Invalid time literal"/utf8>>,
module => <<"tempo/time"/utf8>>,
function => <<"literal"/utf8>>,
line => 179})
end.
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 800).
-spec parse(binary(), binary()) -> {ok, tempo:date()} | {error, tempo:error()}.
parse(Str, Fmt) ->
gleam@result:'try'(
tempo:consume_format(Str, Fmt),
fun(_use0) ->
{Parts, _} = _use0,
tempo:find_date(Parts)
end
).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 821).
-spec parse_any(binary()) -> {ok, tempo:time()} | {error, tempo:error()}.
parse_any(Str) ->
case tempo:parse_any(Str) of
{ok, {_, {some, Time}, _}} ->
{ok, Time};
{ok, {_, none, _}} ->
{error, parse_missing_time};
{error, Err} ->
{error, Err}
end.
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 881).
-spec replace_format(binary(), tempo:time()) -> binary().
replace_format(Content, Time) ->
case Content of
<<"H"/utf8>> ->
_pipe = Time,
_pipe@1 = get_hour(_pipe),
gleam@int:to_string(_pipe@1);
<<"HH"/utf8>> ->
_pipe@2 = Time,
_pipe@3 = get_hour(_pipe@2),
_pipe@4 = gleam@int:to_string(_pipe@3),
gleam@string:pad_left(_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),
gleam@int:to_string(_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 = gleam@int:to_string(_pipe@10),
gleam@string:pad_left(_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),
gleam@int:to_string(_pipe@17);
<<"mm"/utf8>> ->
_pipe@18 = Time,
_pipe@19 = get_minute(_pipe@18),
_pipe@20 = gleam@int:to_string(_pipe@19),
gleam@string:pad_left(_pipe@20, 2, <<"0"/utf8>>);
<<"s"/utf8>> ->
_pipe@21 = Time,
_pipe@22 = get_second(_pipe@21),
gleam@int:to_string(_pipe@22);
<<"ss"/utf8>> ->
_pipe@23 = Time,
_pipe@24 = get_second(_pipe@23),
_pipe@25 = gleam@int:to_string(_pipe@24),
gleam@string:pad_left(_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 = gleam@int:to_string(_pipe@28),
gleam@string:pad_left(_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 = gleam@int:to_string(_pipe@32),
gleam@string:pad_left(_pipe@33, 6, <<"0"/utf8>>);
<<"SSSSS"/utf8>> ->
_pipe@34 = Time,
_pipe@35 = get_nanosecond(_pipe@34),
_pipe@36 = gleam@int:to_string(_pipe@35),
gleam@string:pad_left(_pipe@36, 9, <<"0"/utf8>>);
_ ->
Content
end.
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 859).
-spec format(tempo:time(), binary()) -> binary().
format(Time, 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/time"/utf8>>,
function => <<"format"/utf8>>,
line => 860})
end,
_pipe = gleam@regex: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/Repos/tempo/src/tempo/time.gleam", 1067).
-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/Repos/tempo/src/tempo/time.gleam", 1085).
-spec from_tuple({integer(), integer(), integer()}) -> {ok, tempo:time()} |
{error, tempo:error()}.
from_tuple(Time) ->
new(
erlang:element(1, Time),
erlang:element(2, Time),
erlang:element(3, Time)
).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 1099).
-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/Repos/tempo/src/tempo/time.gleam", 1119).
-spec from_tuple_nanosecond({integer(), integer(), integer(), integer()}) -> {ok,
tempo:time()} |
{error, tempo: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/Repos/tempo/src/tempo/time.gleam", 1205).
-spec compare(tempo:time(), tempo:time()) -> gleam@order:order().
compare(A, B) ->
case {tempo:time_get_mono(A), tempo:time_get_mono(B)} of
{{some, A_mu}, {some, B_mu}} ->
gleam@int:compare(erlang:element(3, A_mu), erlang:element(3, B_mu));
{_, _} ->
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.
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 1265).
-spec is_earlier(tempo:time(), tempo:time()) -> boolean().
is_earlier(A, B) ->
compare(A, B) =:= lt.
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 1289).
-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/Repos/tempo/src/tempo/time.gleam", 1308).
-spec is_equal(tempo:time(), tempo:time()) -> boolean().
is_equal(A, B) ->
compare(A, B) =:= eq.
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 1333).
-spec is_later(tempo:time(), tempo:time()) -> boolean().
is_later(A, B) ->
compare(A, B) =:= gt.
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 1357).
-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/Repos/tempo/src/tempo/time.gleam", 1377).
-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/Repos/tempo/src/tempo/time.gleam", 1400).
-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/Repos/tempo/src/tempo/time.gleam", 1470).
-spec to_nanoseconds(tempo:time()) -> integer().
to_nanoseconds(Time) ->
(((tempo:time_get_hour(Time) * 3600000000000) + (tempo:time_get_minute(Time)
* 60000000000))
+ (tempo:time_get_second(Time) * 1000000000))
+ tempo:time_get_nano(Time).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 1142).
-spec to_duration(tempo:time()) -> tempo:duration().
to_duration(Time) ->
_pipe = to_nanoseconds(Time),
tempo:duration(_pipe).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 1430).
-spec difference(tempo:time(), tempo:time()) -> tempo:duration().
difference(A, B) ->
case {tempo:time_get_mono(A), tempo:time_get_mono(B)} of
{{some, A_mu}, {some, B_mu}} ->
_pipe = (erlang:element(2, A_mu) - erlang:element(2, B_mu)),
tempo:duration(_pipe);
{_, _} ->
_pipe@1 = to_nanoseconds(A) - to_nanoseconds(B),
tempo:duration(_pipe@1)
end.
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 1455).
-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_mu}, {some, B_mu}} ->
erlang:element(2, A_mu) - erlang:element(2, B_mu);
{_, _} ->
to_nanoseconds(A) - 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/Repos/tempo/src/tempo/time.gleam", 1478).
-spec from_nanoseconds(integer()) -> tempo:time().
from_nanoseconds(Nanoseconds) ->
In_range_ns = case 86400000000000 of
0 -> 0;
Gleam@denominator -> Nanoseconds rem Gleam@denominator
end,
Adj_ns = case In_range_ns < 0 of
true ->
In_range_ns + 86400000000000;
false ->
In_range_ns
end,
Hours = Adj_ns div 3600000000000,
Minutes = (Adj_ns - (Hours * 3600000000000)) div 60000000000,
Seconds = ((Adj_ns - (Hours * 3600000000000)) - (Minutes * 60000000000)) div 1000000000,
Nanoseconds@1 = ((Adj_ns - (Hours * 3600000000000)) - (Minutes * 60000000000))
- (Seconds * 1000000000),
tempo:time(Hours, Minutes, Seconds, Nanoseconds@1, nano, none).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 196).
-spec now_utc() -> tempo:time().
now_utc() ->
Now_monotonic = 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 = from_nanoseconds(Now_ts_nano - Date_ts_nano),
tempo:time_set_mono(_pipe, Now_monotonic).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 223).
-spec now_local() -> tempo:time().
now_local() ->
Now_monotonic = 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 = from_nanoseconds(
(Now_ts_nano - Date_ts_nano) + tempo@offset:local_nano()
),
tempo:time_set_mono(_pipe, Now_monotonic).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 978).
-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,
_pipe@1 = from_nanoseconds(_pipe),
to_second_precision(_pipe@1).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 1001).
-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,
_pipe@1 = from_nanoseconds(_pipe),
to_milli_precision(_pipe@1).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 1024).
-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,
_pipe@1 = from_nanoseconds(_pipe),
to_micro_precision(_pipe@1).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 1047).
-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)),
from_nanoseconds(_pipe).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 1180).
-spec from_duration(tempo:duration()) -> tempo:time().
from_duration(Duration) ->
_pipe = Duration,
_pipe@1 = tempo:duration_get_ns(_pipe),
from_nanoseconds(_pipe@1).
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 1515).
-spec add(tempo:time(), tempo:duration()) -> tempo:time().
add(A, B) ->
New_time = begin
_pipe = to_nanoseconds(A) + tempo:duration_get_ns(B),
from_nanoseconds(_pipe)
end,
Adj_time = case begin
_pipe@1 = A,
tempo:time_get_prec(_pipe@1)
end of
sec ->
to_second_precision(New_time);
milli ->
to_milli_precision(New_time);
micro ->
to_micro_precision(New_time);
nano ->
to_nano_precision(New_time)
end,
case tempo:time_get_mono(A) of
none ->
Adj_time;
{some, Mu} ->
_pipe@2 = Adj_time,
tempo:time_set_mono(
_pipe@2,
erlang:setelement(
2,
Mu,
erlang:element(2, Mu) + tempo:duration_get_ns(B)
)
)
end.
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 1547).
-spec subtract(tempo:time(), tempo:duration()) -> tempo:time().
subtract(A, B) ->
New_time = begin
_pipe = to_nanoseconds(A) - tempo:duration_get_ns(B),
from_nanoseconds(_pipe)
end,
Adj_time = case begin
_pipe@1 = A,
tempo:time_get_prec(_pipe@1)
end of
sec ->
to_second_precision(New_time);
milli ->
to_milli_precision(New_time);
micro ->
to_micro_precision(New_time);
nano ->
to_nano_precision(New_time)
end,
case tempo:time_get_mono(A) of
none ->
Adj_time;
{some, Mu} ->
_pipe@2 = Adj_time,
tempo:time_set_mono(
_pipe@2,
erlang:setelement(
2,
Mu,
erlang:element(2, Mu) - tempo:duration_get_ns(B)
)
)
end.
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 1584).
-spec left_in_day(tempo:time()) -> tempo:time().
left_in_day(Time) ->
New_time = begin
_pipe@1 = 86400000000000 - begin
_pipe = Time,
to_nanoseconds(_pipe)
end,
from_nanoseconds(_pipe@1)
end,
case begin
_pipe@2 = Time,
tempo:time_get_prec(_pipe@2)
end of
sec ->
to_second_precision(New_time);
milli ->
to_milli_precision(New_time);
micro ->
to_micro_precision(New_time);
nano ->
to_nano_precision(New_time)
end.
-file("/home/john/Repos/tempo/src/tempo/time.gleam", 1615).
-spec until(tempo:time(), tempo:time()) -> tempo:duration().
until(Time, Until) ->
Dur = begin
_pipe = Time,
_pipe@1 = difference(_pipe, Until),
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/Repos/tempo/src/tempo/time.gleam", 1641).
-spec since(tempo:time(), tempo:time()) -> tempo:duration().
since(Time, Since) ->
Dur = begin
_pipe = Time,
difference(_pipe, Since)
end,
case begin
_pipe@1 = Dur,
tempo@duration:is_negative(_pipe@1)
end of
true ->
tempo@duration:nanoseconds(0);
false ->
Dur
end.