Current section
Files
Jump to
Current section
Files
src/gtempo@internal.erl
-module(gtempo@internal).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/gtempo/internal.gleam").
-export([unit_to_string/1, as_microseconds_fractional/1, as_milliseconds_fractional/1, as_seconds_fractional/1, as_minutes_fractional/1, as_hours_fractional/1, as_days_fractional/1, as_weeks_imprecise_fractional/1, as_months_imprecise_fractional/1, as_years_imprecise_fractional/1, as_unit_fractional/2, format_as/3, in_microseconds/1, format_as_many/3, format/1, as_microseconds/1, as_milliseconds/1, as_seconds/1, as_minutes/1, as_hours/1, as_days_imprecise/1, as_weeks_imprecise/1, as_months_imprecise/1, as_years_imprecise/1, as_unit/2, imprecise_years/1, imprecise_months/1, imprecise_weeks/1, imprecise_days/1, hours/1, minutes/1, seconds/1, milliseconds/1, microseconds/1, floor_div/2, modulo_unwrap/2, div_with_remainder/2, is_letter/1, take_digits/2, take_one_or_two_digits/1, take_digits_up_to/2, skip/2, take_string/2, take_character/1, take_string_up_to/2, take_matched/2, taken_string/2, remaining_string/1, accept_byte/2, accept_empty/1, backtrack/2, scan/2, has_digit_run/2, take_date_parts/1, accept_datetime_delimiter/1, take_time_parts/1, take_offset_minutes/1]).
-export_type([unit/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.
?MODULEDOC(false).
-type unit() :: year |
month |
week |
day |
hour |
{calculated_year, integer(), integer()} |
{calculated_month, integer(), integer()} |
minute |
second |
millisecond |
microsecond |
nothing.
-file("src/gtempo/internal.gleam", 144).
?DOC(false).
-spec unit_to_string(unit()) -> binary().
unit_to_string(Unit) ->
case Unit of
year ->
<<"~year"/utf8>>;
{calculated_year, _, _} ->
<<"year"/utf8>>;
month ->
<<"~month"/utf8>>;
{calculated_month, _, _} ->
<<"month"/utf8>>;
week ->
<<"week"/utf8>>;
day ->
<<"day"/utf8>>;
hour ->
<<"hour"/utf8>>;
minute ->
<<"minute"/utf8>>;
second ->
<<"second"/utf8>>;
millisecond ->
<<"millisecond"/utf8>>;
microsecond ->
<<"microsecond"/utf8>>;
nothing ->
<<"no time"/utf8>>
end.
-file("src/gtempo/internal.gleam", 316).
?DOC(false).
-spec as_microseconds_fractional(integer()) -> float().
as_microseconds_fractional(Microseconds) ->
erlang:float(Microseconds).
-file("src/gtempo/internal.gleam", 308).
?DOC(false).
-spec as_milliseconds_fractional(integer()) -> float().
as_milliseconds_fractional(Microseconds) ->
case erlang:float(1000) of
+0.0 -> +0.0;
-0.0 -> -0.0;
Gleam@denominator -> erlang:float(Microseconds) / Gleam@denominator
end.
-file("src/gtempo/internal.gleam", 300).
?DOC(false).
-spec as_seconds_fractional(integer()) -> float().
as_seconds_fractional(Microseconds) ->
case erlang:float(1000000) of
+0.0 -> +0.0;
-0.0 -> -0.0;
Gleam@denominator -> erlang:float(Microseconds) / Gleam@denominator
end.
-file("src/gtempo/internal.gleam", 292).
?DOC(false).
-spec as_minutes_fractional(integer()) -> float().
as_minutes_fractional(Microseconds) ->
case erlang:float(60000000) of
+0.0 -> +0.0;
-0.0 -> -0.0;
Gleam@denominator -> erlang:float(Microseconds) / Gleam@denominator
end.
-file("src/gtempo/internal.gleam", 284).
?DOC(false).
-spec as_hours_fractional(integer()) -> float().
as_hours_fractional(Microseconds) ->
case erlang:float(3600000000) of
+0.0 -> +0.0;
-0.0 -> -0.0;
Gleam@denominator -> erlang:float(Microseconds) / Gleam@denominator
end.
-file("src/gtempo/internal.gleam", 276).
?DOC(false).
-spec as_days_fractional(integer()) -> float().
as_days_fractional(Microseconds) ->
case erlang:float(86400000000) of
+0.0 -> +0.0;
-0.0 -> -0.0;
Gleam@denominator -> erlang:float(Microseconds) / Gleam@denominator
end.
-file("src/gtempo/internal.gleam", 268).
?DOC(false).
-spec as_weeks_imprecise_fractional(integer()) -> float().
as_weeks_imprecise_fractional(Microseconds) ->
case erlang:float(604800000000) of
+0.0 -> +0.0;
-0.0 -> -0.0;
Gleam@denominator -> erlang:float(Microseconds) / Gleam@denominator
end.
-file("src/gtempo/internal.gleam", 260).
?DOC(false).
-spec as_months_imprecise_fractional(integer()) -> float().
as_months_imprecise_fractional(Microseconds) ->
case erlang:float(2592000000000) of
+0.0 -> +0.0;
-0.0 -> -0.0;
Gleam@denominator -> erlang:float(Microseconds) / Gleam@denominator
end.
-file("src/gtempo/internal.gleam", 252).
?DOC(false).
-spec as_years_imprecise_fractional(integer()) -> float().
as_years_imprecise_fractional(Microseconds) ->
case erlang:float(31449600000000) of
+0.0 -> +0.0;
-0.0 -> -0.0;
Gleam@denominator -> erlang:float(Microseconds) / Gleam@denominator
end.
-file("src/gtempo/internal.gleam", 195).
?DOC(false).
-spec as_unit_fractional(integer(), unit()) -> float().
as_unit_fractional(Microseconds, Unit) ->
case Unit of
year ->
as_years_imprecise_fractional(Microseconds);
{calculated_year, Years, _} ->
_pipe = Years,
erlang:float(_pipe);
month ->
as_months_imprecise_fractional(Microseconds);
{calculated_month, Months, _} ->
_pipe@1 = Months,
erlang:float(_pipe@1);
week ->
as_weeks_imprecise_fractional(Microseconds);
day ->
as_days_fractional(Microseconds);
hour ->
as_hours_fractional(Microseconds);
minute ->
as_minutes_fractional(Microseconds);
second ->
as_seconds_fractional(Microseconds);
millisecond ->
as_milliseconds_fractional(Microseconds);
microsecond ->
as_microseconds_fractional(Microseconds);
nothing ->
+0.0
end.
-file("src/gtempo/internal.gleam", 63).
?DOC(false).
-spec format_as(integer(), unit(), integer()) -> binary().
format_as(Microseconds, Unit, Decimals) ->
In_unit = as_unit_fractional(Microseconds, Unit),
Decimal = begin
_pipe = erlang:trunc(In_unit),
_pipe@1 = erlang:float(_pipe),
gleam@float:subtract(In_unit, _pipe@1)
end,
Decimal_formatted = begin
_pipe@2 = Decimal,
_pipe@3 = gleam_stdlib:float_to_string(_pipe@2),
_pipe@4 = gleam@string:slice(_pipe@3, 2, Decimals),
gleam@string:pad_end(_pipe@4, Decimals, <<"0"/utf8>>)
end,
Whole = begin
_pipe@5 = erlang:trunc(In_unit),
erlang:integer_to_binary(_pipe@5)
end,
<<<<<<<<<<Whole/binary, (case Decimals > 0 of
true ->
<<"."/utf8>>;
false ->
<<""/utf8>>
end)/binary>>/binary, Decimal_formatted/binary>>/binary, " "/utf8>>/binary, (unit_to_string(
Unit
))/binary>>/binary, (case ((Whole =:= <<"1"/utf8>>) orelse (Whole
=:= <<"-1"/utf8>>))
andalso (Decimal =:= +0.0) of
true ->
<<""/utf8>>;
false ->
<<"s"/utf8>>
end)/binary>>.
-file("src/gtempo/internal.gleam", 161).
?DOC(false).
-spec in_microseconds(unit()) -> integer().
in_microseconds(Unit) ->
case Unit of
year ->
31449600000000;
month ->
2592000000000;
week ->
604800000000;
day ->
86400000000;
{calculated_year, _, Microseconds} ->
Microseconds;
{calculated_month, _, Microseconds@1} ->
Microseconds@1;
hour ->
3600000000;
minute ->
60000000;
second ->
1000000;
millisecond ->
1000;
microsecond ->
1;
nothing ->
0
end.
-file("src/gtempo/internal.gleam", 99).
?DOC(false).
-spec format_as_many(integer(), list(unit()), integer()) -> binary().
format_as_many(Microseconds, Units, Decimals) ->
erlang:element(
2,
gleam@list:index_fold(
Units,
{Microseconds, <<""/utf8>>},
fun(Accumulator, Unit, I) ->
case erlang:length(Units) =:= (I + 1) of
true ->
{0,
<<<<(erlang:element(2, Accumulator))/binary,
(case erlang:length(Units) /= 1 of
true ->
<<"and "/utf8>>;
false ->
<<""/utf8>>
end)/binary>>/binary,
(format_as(
erlang:element(1, Accumulator),
Unit,
Decimals
))/binary>>};
false ->
Remaining_duration = case in_microseconds(Unit) of
0 -> 0;
Gleam@denominator -> Microseconds rem Gleam@denominator
end,
Formated_current_unit = begin
_pipe = erlang:element(1, Accumulator) - Remaining_duration,
format_as(_pipe, Unit, 0)
end,
{Remaining_duration,
<<<<(erlang:element(2, Accumulator))/binary,
Formated_current_unit/binary>>/binary,
(case erlang:length(Units) > 2 of
true ->
<<", "/utf8>>;
false ->
<<" "/utf8>>
end)/binary>>}
end
end
)
).
-file("src/gtempo/internal.gleam", 43).
?DOC(false).
-spec format(integer()) -> binary().
format(Microseconds) ->
case Microseconds of
N when N >= 31449600000000 ->
format_as_many(Microseconds, [year, week, day, hour, minute], 0);
N@1 when N@1 >= 604800000000 ->
format_as_many(Microseconds, [week, day, hour, minute], 0);
N@2 when N@2 >= 86400000000 ->
format_as_many(Microseconds, [day, hour, minute], 0);
N@3 when N@3 >= 3600000000 ->
format_as_many(Microseconds, [hour, minute, second], 2);
N@4 when N@4 >= 60000000 ->
format_as_many(Microseconds, [minute, second], 3);
N@5 when N@5 >= 1000000 ->
format_as(Microseconds, second, 3);
N@6 when N@6 >= 1000 ->
format_as(Microseconds, millisecond, 0);
_ ->
format_as(Microseconds, microsecond, 0)
end.
-file("src/gtempo/internal.gleam", 312).
?DOC(false).
-spec as_microseconds(integer()) -> integer().
as_microseconds(Microseconds) ->
Microseconds.
-file("src/gtempo/internal.gleam", 304).
?DOC(false).
-spec as_milliseconds(integer()) -> integer().
as_milliseconds(Microseconds) ->
case 1000 of
0 -> 0;
Gleam@denominator -> Microseconds div Gleam@denominator
end.
-file("src/gtempo/internal.gleam", 296).
?DOC(false).
-spec as_seconds(integer()) -> integer().
as_seconds(Microseconds) ->
case 1000000 of
0 -> 0;
Gleam@denominator -> Microseconds div Gleam@denominator
end.
-file("src/gtempo/internal.gleam", 288).
?DOC(false).
-spec as_minutes(integer()) -> integer().
as_minutes(Microseconds) ->
case 60000000 of
0 -> 0;
Gleam@denominator -> Microseconds div Gleam@denominator
end.
-file("src/gtempo/internal.gleam", 280).
?DOC(false).
-spec as_hours(integer()) -> integer().
as_hours(Microseconds) ->
case 3600000000 of
0 -> 0;
Gleam@denominator -> Microseconds div Gleam@denominator
end.
-file("src/gtempo/internal.gleam", 272).
?DOC(false).
-spec as_days_imprecise(integer()) -> integer().
as_days_imprecise(Microseconds) ->
case 86400000000 of
0 -> 0;
Gleam@denominator -> Microseconds div Gleam@denominator
end.
-file("src/gtempo/internal.gleam", 264).
?DOC(false).
-spec as_weeks_imprecise(integer()) -> integer().
as_weeks_imprecise(Microseconds) ->
case 604800000000 of
0 -> 0;
Gleam@denominator -> Microseconds div Gleam@denominator
end.
-file("src/gtempo/internal.gleam", 256).
?DOC(false).
-spec as_months_imprecise(integer()) -> integer().
as_months_imprecise(Microseconds) ->
case 2592000000000 of
0 -> 0;
Gleam@denominator -> Microseconds div Gleam@denominator
end.
-file("src/gtempo/internal.gleam", 248).
?DOC(false).
-spec as_years_imprecise(integer()) -> integer().
as_years_imprecise(Microseconds) ->
case 31449600000000 of
0 -> 0;
Gleam@denominator -> Microseconds div Gleam@denominator
end.
-file("src/gtempo/internal.gleam", 178).
?DOC(false).
-spec as_unit(integer(), unit()) -> integer().
as_unit(Microseconds, Unit) ->
case Unit of
year ->
as_years_imprecise(Microseconds);
{calculated_year, Years, _} ->
Years;
month ->
as_months_imprecise(Microseconds);
{calculated_month, Months, _} ->
Months;
week ->
as_weeks_imprecise(Microseconds);
day ->
as_days_imprecise(Microseconds);
hour ->
as_hours(Microseconds);
minute ->
as_minutes(Microseconds);
second ->
as_seconds(Microseconds);
millisecond ->
as_milliseconds(Microseconds);
microsecond ->
as_microseconds(Microseconds);
nothing ->
0
end.
-file("src/gtempo/internal.gleam", 212).
?DOC(false).
-spec imprecise_years(integer()) -> integer().
imprecise_years(Years) ->
Years * 31449600000000.
-file("src/gtempo/internal.gleam", 216).
?DOC(false).
-spec imprecise_months(integer()) -> integer().
imprecise_months(Months) ->
Months * 2592000000000.
-file("src/gtempo/internal.gleam", 220).
?DOC(false).
-spec imprecise_weeks(integer()) -> integer().
imprecise_weeks(Weeks) ->
Weeks * 604800000000.
-file("src/gtempo/internal.gleam", 224).
?DOC(false).
-spec imprecise_days(integer()) -> integer().
imprecise_days(Days) ->
Days * 86400000000.
-file("src/gtempo/internal.gleam", 228).
?DOC(false).
-spec hours(integer()) -> integer().
hours(Hours) ->
Hours * 3600000000.
-file("src/gtempo/internal.gleam", 232).
?DOC(false).
-spec minutes(integer()) -> integer().
minutes(Minutes) ->
Minutes * 60000000.
-file("src/gtempo/internal.gleam", 236).
?DOC(false).
-spec seconds(integer()) -> integer().
seconds(Seconds) ->
Seconds * 1000000.
-file("src/gtempo/internal.gleam", 240).
?DOC(false).
-spec milliseconds(integer()) -> integer().
milliseconds(Milliseconds) ->
Milliseconds * 1000.
-file("src/gtempo/internal.gleam", 244).
?DOC(false).
-spec microseconds(integer()) -> integer().
microseconds(Microseconds) ->
Microseconds.
-file("src/gtempo/internal.gleam", 322).
?DOC(false).
-spec floor_div(integer(), integer()) -> integer().
floor_div(Dividend, Divisor) ->
case (((Dividend > 0) andalso (Divisor < 0)) orelse ((Dividend < 0) andalso (Divisor
> 0)))
andalso ((case Divisor of
0 -> 0;
Gleam@denominator -> Dividend rem Gleam@denominator
end) /= 0) of
true ->
(case Divisor of
0 -> 0;
Gleam@denominator@1 -> Dividend div Gleam@denominator@1
end) - 1;
false ->
case Divisor of
0 -> 0;
Gleam@denominator@2 -> Dividend div Gleam@denominator@2
end
end.
-file("src/gtempo/internal.gleam", 338).
?DOC(false).
-spec modulo_unwrap(integer(), integer()) -> integer().
modulo_unwrap(Dividend, Divisor) ->
Remainder = case Divisor of
0 -> 0;
Gleam@denominator -> Dividend rem Gleam@denominator
end,
case ((Remainder > 0) andalso (Divisor < 0)) orelse ((Remainder < 0) andalso (Divisor
> 0)) of
true ->
Remainder + Divisor;
false ->
Remainder
end.
-file("src/gtempo/internal.gleam", 332).
?DOC(false).
-spec div_with_remainder(integer(), integer()) -> {integer(), integer()}.
div_with_remainder(A, B) ->
{floor_div(A, B), modulo_unwrap(A, B)}.
-file("src/gtempo/internal.gleam", 366).
?DOC(false).
-spec is_letter(integer()) -> boolean().
is_letter(Byte) ->
((16#41 =< Byte) andalso (Byte =< 16#5A)) orelse ((16#61 =< Byte) andalso (Byte
=< 16#7A)).
-file("src/gtempo/internal.gleam", 380).
?DOC(false).
-spec do_take_digits(bitstring(), integer(), integer()) -> {ok,
{integer(), bitstring()}} |
{error, nil}.
do_take_digits(Bytes, Count, Acc) ->
case Bytes of
_ when Count =< 0 ->
{ok, {Acc, Bytes}};
<<Byte, Rest/binary>> when (16#30 =< Byte) andalso (Byte =< 16#39) ->
do_take_digits(Rest, Count - 1, (Acc * 10) + (Byte - 16#30));
_ ->
{error, nil}
end.
-file("src/gtempo/internal.gleam", 373).
?DOC(false).
-spec take_digits(bitstring(), integer()) -> {ok, {integer(), bitstring()}} |
{error, nil}.
take_digits(Bytes, Count) ->
do_take_digits(Bytes, Count, 0).
-file("src/gtempo/internal.gleam", 395).
?DOC(false).
-spec take_one_or_two_digits(bitstring()) -> {ok, {integer(), bitstring()}} |
{error, nil}.
take_one_or_two_digits(Bytes) ->
_pipe = take_digits(Bytes, 2),
gleam@result:try_recover(_pipe, fun(_) -> take_digits(Bytes, 1) end).
-file("src/gtempo/internal.gleam", 413).
?DOC(false).
-spec do_take_digits_up_to(bitstring(), integer(), integer(), integer()) -> {integer(),
integer(),
bitstring()}.
do_take_digits_up_to(Bytes, Limit, Acc, Taken) ->
case Bytes of
<<Byte, Rest/binary>> when ((Taken < Limit) andalso (16#30 =< Byte)) andalso (Byte =< 16#39) ->
do_take_digits_up_to(
Rest,
Limit,
(Acc * 10) + (Byte - 16#30),
Taken + 1
);
_ ->
{Acc, Taken, Bytes}
end.
-file("src/gtempo/internal.gleam", 406).
?DOC(false).
-spec take_digits_up_to(bitstring(), integer()) -> {integer(),
integer(),
bitstring()}.
take_digits_up_to(Bytes, Limit) ->
do_take_digits_up_to(Bytes, Limit, 0, 0).
-file("src/gtempo/internal.gleam", 435).
?DOC(false).
-spec skip(bitstring(), integer()) -> {ok, bitstring()} | {error, nil}.
skip(Bytes, Count) ->
case Count =< 0 of
true ->
{ok, Bytes};
false ->
case Bytes of
<<_, Rest/binary>> ->
skip(Rest, Count - 1);
_ ->
{error, nil}
end
end.
-file("src/gtempo/internal.gleam", 448).
?DOC(false).
-spec take_string(bitstring(), integer()) -> {ok, {binary(), bitstring()}} |
{error, nil}.
take_string(Bytes, Count) ->
case gleam_stdlib:bit_array_slice(Bytes, 0, Count) of
{ok, Taken} ->
case {gleam@bit_array:to_string(Taken), skip(Bytes, Count)} of
{{ok, Taken@1}, {ok, Rest}} ->
{ok, {Taken@1, Rest}};
{_, _} ->
{error, nil}
end;
{error, nil} ->
{error, nil}
end.
-file("src/gtempo/internal.gleam", 466).
?DOC(false).
-spec take_character(bitstring()) -> {ok, {binary(), bitstring()}} |
{error, nil}.
take_character(Bytes) ->
Length = case Bytes of
<<Byte, _/binary>> when Byte < 16#80 ->
1;
<<Byte@1, _/binary>> when Byte@1 < 16#E0 ->
2;
<<Byte@2, _/binary>> when Byte@2 < 16#F0 ->
3;
_ ->
4
end,
take_string(Bytes, Length).
-file("src/gtempo/internal.gleam", 490).
?DOC(false).
-spec do_take_string_up_to(bitstring(), integer(), list(binary())) -> {binary(),
bitstring()}.
do_take_string_up_to(Bytes, Count, Acc) ->
case {Count =< 0, take_character(Bytes)} of
{false, {ok, {Character, Rest}}} ->
do_take_string_up_to(Rest, Count - 1, [Character | Acc]);
{_, _} ->
{begin
_pipe = Acc,
_pipe@1 = lists:reverse(_pipe),
erlang:list_to_binary(_pipe@1)
end,
Bytes}
end.
-file("src/gtempo/internal.gleam", 483).
?DOC(false).
-spec take_string_up_to(bitstring(), integer()) -> {binary(), bitstring()}.
take_string_up_to(Bytes, Count) ->
do_take_string_up_to(Bytes, Count, []).
-file("src/gtempo/internal.gleam", 532).
?DOC(false).
-spec taken_length(bitstring(), bitstring()) -> integer().
taken_length(Bytes, Rest) ->
erlang:byte_size(Bytes) - erlang:byte_size(Rest).
-file("src/gtempo/internal.gleam", 506).
?DOC(false).
-spec take_matched(
bitstring(),
fun((bitstring()) -> {ok, bitstring()} | {error, nil})
) -> {ok, {binary(), bitstring()}} | {error, nil}.
take_matched(Bytes, Matcher) ->
gleam@result:'try'(
Matcher(Bytes),
fun(Rest) ->
gleam@result:map(
take_string(Bytes, taken_length(Bytes, Rest)),
fun(_use0) ->
{Matched, _} = _use0,
{Matched, Rest}
end
)
end
).
-file("src/gtempo/internal.gleam", 519).
?DOC(false).
-spec taken_string(bitstring(), bitstring()) -> binary().
taken_string(Bytes, Rest) ->
case take_string(Bytes, taken_length(Bytes, Rest)) of
{ok, {Taken, _}} ->
Taken;
{error, nil} ->
<<""/utf8>>
end.
-file("src/gtempo/internal.gleam", 528).
?DOC(false).
-spec remaining_string(bitstring()) -> binary().
remaining_string(Bytes) ->
_pipe = gleam@bit_array:to_string(Bytes),
gleam@result:unwrap(_pipe, <<""/utf8>>).
-file("src/gtempo/internal.gleam", 538).
?DOC(false).
-spec accept_byte(bitstring(), integer()) -> {ok, bitstring()} | {error, nil}.
accept_byte(Bytes, Value) ->
case Bytes of
<<Byte, Rest/binary>> when Byte =:= Value ->
{ok, Rest};
_ ->
{error, nil}
end.
-file("src/gtempo/internal.gleam", 550).
?DOC(false).
-spec accept_empty(bitstring()) -> {ok, nil} | {error, nil}.
accept_empty(Bytes) ->
case Bytes of
<<>> ->
{ok, nil};
_ ->
{error, nil}
end.
-file("src/gtempo/internal.gleam", 562).
?DOC(false).
-spec backtrack(list(DYM), fun((DYM) -> {ok, DYO} | {error, nil})) -> {ok, DYO} |
{error, nil}.
backtrack(Options, Body) ->
case Options of
[] ->
{error, nil};
[Option | Options@1] ->
case Body(Option) of
{ok, Value} ->
{ok, Value};
{error, nil} ->
backtrack(Options@1, Body)
end
end.
-file("src/gtempo/internal.gleam", 590).
?DOC(false).
-spec do_scan(
bitstring(),
fun((bitstring()) -> {ok, {DYY, bitstring()}} | {error, nil}),
integer(),
integer()
) -> {ok, {DYY, bitstring()}} | {error, nil}.
do_scan(Bytes, Matcher, Offset, Size) ->
case Offset > Size of
true ->
{error, nil};
false ->
Tail@1 = case gleam_stdlib:bit_array_slice(
Bytes,
Offset,
Size - Offset
) of
{ok, Tail} -> Tail;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"gtempo/internal"/utf8>>,
function => <<"do_scan"/utf8>>,
line => 599,
value => _assert_fail,
start => 16621,
'end' => 16688,
pattern_start => 16632,
pattern_end => 16640})
end,
case Matcher(Tail@1) of
{error, nil} ->
do_scan(Bytes, Matcher, Offset + 1, Size);
{ok, {Value, Rest}} ->
Head@1 = case gleam_stdlib:bit_array_slice(Bytes, 0, Offset) of
{ok, Head} -> Head;
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"gtempo/internal"/utf8>>,
function => <<"do_scan"/utf8>>,
line => 604,
value => _assert_fail@1,
start => 16823,
'end' => 16878,
pattern_start => 16834,
pattern_end => 16842})
end,
{ok, {Value, <<Head@1/bitstring, Rest/bitstring>>}}
end
end.
-file("src/gtempo/internal.gleam", 583).
?DOC(false).
-spec scan(
bitstring(),
fun((bitstring()) -> {ok, {DYT, bitstring()}} | {error, nil})
) -> {ok, {DYT, bitstring()}} | {error, nil}.
scan(Bytes, Matcher) ->
do_scan(Bytes, Matcher, 0, erlang:byte_size(Bytes)).
-file("src/gtempo/internal.gleam", 618).
?DOC(false).
-spec do_has_digit_run(bitstring(), integer(), integer()) -> boolean().
do_has_digit_run(Bytes, Count, Run) ->
case Bytes of
_ when Run >= Count ->
true;
<<Byte, Rest/binary>> when (16#30 =< Byte) andalso (Byte =< 16#39) ->
do_has_digit_run(Rest, Count, Run + 1);
<<_, Rest@1/binary>> ->
do_has_digit_run(Rest@1, Count, 0);
_ ->
false
end.
-file("src/gtempo/internal.gleam", 614).
?DOC(false).
-spec has_digit_run(bitstring(), integer()) -> boolean().
has_digit_run(Bytes, Count) ->
do_has_digit_run(Bytes, Count, 0).
-file("src/gtempo/internal.gleam", 664).
?DOC(false).
-spec take_condensed_date(bitstring()) -> {ok,
{{integer(), integer(), integer()}, bitstring()}} |
{error, nil}.
take_condensed_date(Input) ->
gleam@result:'try'(
take_digits(Input, 4),
fun(_use0) ->
{Year, Input@1} = _use0,
gleam@result:'try'(
take_digits(Input@1, 2),
fun(_use0@1) ->
{Month, Input@2} = _use0@1,
gleam@result:map(
take_digits(Input@2, 2),
fun(_use0@2) ->
{Day, Input@3} = _use0@2,
{{Year, Month, Day}, Input@3}
end
)
end
)
end
).
-file("src/gtempo/internal.gleam", 674).
?DOC(false).
-spec take_date_delimiter(bitstring()) -> {ok, {integer(), bitstring()}} |
{error, nil}.
take_date_delimiter(Input) ->
case Input of
<<Delimiter, Input@1/binary>> when ((((Delimiter =:= 16#2D) orelse (Delimiter =:= 16#2F)) orelse (Delimiter =:= 16#2E)) orelse (Delimiter =:= 16#5F)) orelse (Delimiter =:= 16#20) ->
{ok, {Delimiter, Input@1}};
_ ->
{error, nil}
end.
-file("src/gtempo/internal.gleam", 648).
?DOC(false).
-spec take_delimited_date(bitstring()) -> {ok,
{{integer(), integer(), integer()}, bitstring()}} |
{error, nil}.
take_delimited_date(Input) ->
{Year, Year_digits, Input@1} = take_digits_up_to(Input, 10),
gleam@bool:guard(
Year_digits =:= 0,
{error, nil},
fun() ->
gleam@result:'try'(
take_date_delimiter(Input@1),
fun(_use0) ->
{Delimiter, Input@2} = _use0,
gleam@result:'try'(
take_one_or_two_digits(Input@2),
fun(_use0@1) ->
{Month, Input@3} = _use0@1,
gleam@result:'try'(
accept_byte(Input@3, Delimiter),
fun(Input@4) ->
gleam@result:map(
take_one_or_two_digits(Input@4),
fun(_use0@2) ->
{Day, Input@5} = _use0@2,
{{Year, Month, Day}, Input@5}
end
)
end
)
end
)
end
)
end
).
-file("src/gtempo/internal.gleam", 638).
?DOC(false).
-spec take_date_parts(bitstring()) -> {ok,
{{integer(), integer(), integer()}, bitstring()}} |
{error, nil}.
take_date_parts(Input) ->
_pipe = take_delimited_date(Input),
gleam@result:try_recover(_pipe, fun(_) -> take_condensed_date(Input) end).
-file("src/gtempo/internal.gleam", 690).
?DOC(false).
-spec accept_datetime_delimiter(bitstring()) -> {ok, bitstring()} | {error, nil}.
accept_datetime_delimiter(Input) ->
case Input of
<<Delimiter, Input@1/binary>> when (((Delimiter =:= 16#54) orelse (Delimiter =:= 16#74)) orelse (Delimiter =:= 16#5F)) orelse (Delimiter =:= 16#20) ->
{ok, Input@1};
_ ->
{error, nil}
end.
-file("src/gtempo/internal.gleam", 770).
?DOC(false).
-spec take_second_fraction(bitstring()) -> {ok, {integer(), bitstring()}} |
{error, nil}.
take_second_fraction(Input) ->
case Input of
<<"."/utf8, Input@1/binary>> ->
{Fraction, Digits, Input@2} = take_digits_up_to(Input@1, 6),
case Input@2 of
<<Byte, _/binary>> when (16#30 =< Byte) andalso (Byte =< 16#39) ->
{error, nil};
_ ->
{ok, {case Digits of
0 ->
0;
1 ->
Fraction * 100000;
2 ->
Fraction * 10000;
3 ->
Fraction * 1000;
4 ->
Fraction * 100;
5 ->
Fraction * 10;
_ ->
Fraction
end, Input@2}}
end;
_ ->
{ok, {0, Input}}
end.
-file("src/gtempo/internal.gleam", 759).
?DOC(false).
-spec take_condensed_second(bitstring()) -> {ok,
{integer(), integer(), bitstring()}} |
{error, nil}.
take_condensed_second(Input) ->
gleam@result:'try'(
take_digits(Input, 2),
fun(_use0) ->
{Second, Input@1} = _use0,
gleam@result:map(
take_second_fraction(Input@1),
fun(_use0@1) ->
{Microsecond, Input@2} = _use0@1,
{Second, Microsecond, Input@2}
end
)
end
).
-file("src/gtempo/internal.gleam", 744).
?DOC(false).
-spec take_condensed_time(bitstring()) -> {ok,
{{integer(), integer(), integer(), integer()}, bitstring()}} |
{error, nil}.
take_condensed_time(Input) ->
gleam@result:'try'(
take_digits(Input, 2),
fun(_use0) ->
{Hour, Input@1} = _use0,
gleam@result:map(
take_digits(Input@1, 2),
fun(_use0@1) ->
{Minute, Input@2} = _use0@1,
case take_condensed_second(Input@2) of
{ok, {Second, Microsecond, Input@3}} ->
{{Hour, Minute, Second, Microsecond}, Input@3};
{error, nil} ->
{{Hour, Minute, 0, 0}, Input@2}
end
end
)
end
).
-file("src/gtempo/internal.gleam", 732).
?DOC(false).
-spec take_delimited_second(bitstring()) -> {ok,
{integer(), integer(), bitstring()}} |
{error, nil}.
take_delimited_second(Input) ->
gleam@result:'try'(
accept_byte(Input, 16#3A),
fun(Input@1) ->
gleam@result:'try'(
take_one_or_two_digits(Input@1),
fun(_use0) ->
{Second, Input@2} = _use0,
gleam@result:map(
take_second_fraction(Input@2),
fun(_use0@1) ->
{Microsecond, Input@3} = _use0@1,
{Second, Microsecond, Input@3}
end
)
end
)
end
).
-file("src/gtempo/internal.gleam", 715).
?DOC(false).
-spec take_delimited_time(bitstring()) -> {ok,
{{integer(), integer(), integer(), integer()}, bitstring()}} |
{error, nil}.
take_delimited_time(Input) ->
gleam@result:'try'(
take_one_or_two_digits(Input),
fun(_use0) ->
{Hour, Input@1} = _use0,
gleam@result:'try'(
accept_byte(Input@1, 16#3A),
fun(Input@2) ->
gleam@result:map(
take_one_or_two_digits(Input@2),
fun(_use0@1) ->
{Minute, Input@3} = _use0@1,
case take_delimited_second(Input@3) of
{ok, {Second, Microsecond, Input@4}} ->
{{Hour, Minute, Second, Microsecond},
Input@4};
{error, nil} ->
{{Hour, Minute, 0, 0}, Input@3}
end
end
)
end
)
end
).
-file("src/gtempo/internal.gleam", 706).
?DOC(false).
-spec take_time_parts(bitstring()) -> {ok,
{{integer(), integer(), integer(), integer()}, bitstring()}} |
{error, nil}.
take_time_parts(Input) ->
_pipe = take_delimited_time(Input),
gleam@result:try_recover(_pipe, fun(_) -> take_condensed_time(Input) end).
-file("src/gtempo/internal.gleam", 860).
?DOC(false).
-spec take_hour_offset(bitstring()) -> {ok, {integer(), integer(), bitstring()}} |
{error, nil}.
take_hour_offset(Input) ->
gleam@result:map(
take_one_or_two_digits(Input),
fun(_use0) ->
{Hours, Input@1} = _use0,
{Hours, 0, Input@1}
end
).
-file("src/gtempo/internal.gleam", 851).
?DOC(false).
-spec take_hour_minute_offset(bitstring()) -> {ok,
{integer(), integer(), bitstring()}} |
{error, nil}.
take_hour_minute_offset(Input) ->
gleam@result:'try'(
take_digits(Input, 2),
fun(_use0) ->
{Hours, Input@1} = _use0,
gleam@result:map(
take_digits(Input@1, 2),
fun(_use0@1) ->
{Minutes, Input@2} = _use0@1,
{Hours, Minutes, Input@2}
end
)
end
).
-file("src/gtempo/internal.gleam", 841).
?DOC(false).
-spec take_hour_colon_minute_offset(bitstring()) -> {ok,
{integer(), integer(), bitstring()}} |
{error, nil}.
take_hour_colon_minute_offset(Input) ->
gleam@result:'try'(
take_digits(Input, 2),
fun(_use0) ->
{Hours, Input@1} = _use0,
gleam@result:'try'(
accept_byte(Input@1, 16#3A),
fun(Input@2) ->
gleam@result:map(
take_digits(Input@2, 2),
fun(_use0@1) ->
{Minutes, Input@3} = _use0@1,
{Hours, Minutes, Input@3}
end
)
end
)
end
).
-file("src/gtempo/internal.gleam", 833).
?DOC(false).
-spec take_offset_direction(bitstring()) -> {ok, {boolean(), bitstring()}} |
{error, nil}.
take_offset_direction(Input) ->
case Input of
<<"-"/utf8, Input@1/binary>> ->
{ok, {true, Input@1}};
<<"+"/utf8, Input@2/binary>> ->
{ok, {false, Input@2}};
_ ->
{error, nil}
end.
-file("src/gtempo/internal.gleam", 812).
?DOC(false).
-spec take_numeric_offset_minutes(bitstring()) -> {ok, {integer(), bitstring()}} |
{error, nil}.
take_numeric_offset_minutes(Input) ->
gleam@result:'try'(
take_offset_direction(Input),
fun(_use0) ->
{Is_negative, Input@1} = _use0,
gleam@result:'try'(
begin
_pipe = take_hour_colon_minute_offset(Input@1),
_pipe@1 = gleam@result:try_recover(
_pipe,
fun(_) -> take_hour_minute_offset(Input@1) end
),
gleam@result:try_recover(
_pipe@1,
fun(_) -> take_hour_offset(Input@1) end
)
end,
fun(_use0@1) ->
{Hours, Minutes, Input@2} = _use0@1,
case (Hours =< 24) andalso (Minutes =< 60) of
false ->
{error, nil};
true ->
case Is_negative of
true ->
{ok, {- ((Hours * 60) + Minutes), Input@2}};
false ->
{ok, {(Hours * 60) + Minutes, Input@2}}
end
end
end
)
end
).
-file("src/gtempo/internal.gleam", 803).
?DOC(false).
-spec take_offset_minutes(bitstring()) -> {ok, {integer(), bitstring()}} |
{error, nil}.
take_offset_minutes(Input) ->
case Input of
<<"Z"/utf8, Input@1/binary>> ->
{ok, {0, Input@1}};
<<"z"/utf8, Input@1/binary>> ->
{ok, {0, Input@1}};
_ ->
take_numeric_offset_minutes(Input)
end.