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]).
-export([unit_to_string/1, nanoseconds/1, as_nanoseconds/1, imprecise_years/1, as_years_imprecise/1, as_years_imprecise_fractional/1, imprecise_months/1, as_months_imprecise/1, as_months_imprecise_fractional/1, imprecise_weeks/1, as_weeks_imprecise/1, as_weeks_imprecise_fractional/1, imprecise_days/1, as_days_imprecise/1, as_days_fractional/1, hours/1, as_hours/1, as_hours_fractional/1, minutes/1, as_minutes/1, as_minutes_fractional/1, seconds/1, as_seconds/1, as_seconds_fractional/1, milliseconds/1, as_milliseconds/1, as_milliseconds_fractional/1, in_nanoseconds/1, microseconds/1, as_microseconds/1, as_unit/2, as_microseconds_fractional/1, as_unit_fractional/2, format_as/3, format_as_many/3]).
-export_type([unit/0]).
-type unit() :: year |
month |
week |
day |
hour |
{calculated_year, integer(), integer()} |
{calculated_month, integer(), integer()} |
minute |
second |
millisecond |
microsecond |
nanosecond |
nothing.
-file("/home/john/tempo/src/gtempo/internal.gleam", 119).
-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>>;
nanosecond ->
<<"nanosecond"/utf8>>;
nothing ->
<<"no time"/utf8>>
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 227).
-spec nanoseconds(integer()) -> integer().
nanoseconds(Nanoseconds) ->
Nanoseconds.
-file("/home/john/tempo/src/gtempo/internal.gleam", 303).
-spec as_nanoseconds(integer()) -> integer().
as_nanoseconds(Nanoseconds) ->
Nanoseconds.
-file("/home/john/tempo/src/gtempo/internal.gleam", 191).
-spec imprecise_years(integer()) -> integer().
imprecise_years(Years) ->
Years * 31449600000000000.
-file("/home/john/tempo/src/gtempo/internal.gleam", 231).
-spec as_years_imprecise(integer()) -> integer().
as_years_imprecise(Nanoseconds) ->
case 31449600000000000 of
0 -> 0;
Gleam@denominator -> Nanoseconds div Gleam@denominator
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 235).
-spec as_years_imprecise_fractional(integer()) -> float().
as_years_imprecise_fractional(Nanoseconds) ->
case erlang:float(31449600000000000) of
+0.0 -> +0.0;
-0.0 -> -0.0;
Gleam@denominator -> erlang:float(Nanoseconds) / Gleam@denominator
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 195).
-spec imprecise_months(integer()) -> integer().
imprecise_months(Months) ->
Months * 2592000000000000.
-file("/home/john/tempo/src/gtempo/internal.gleam", 239).
-spec as_months_imprecise(integer()) -> integer().
as_months_imprecise(Nanoseconds) ->
case 2592000000000000 of
0 -> 0;
Gleam@denominator -> Nanoseconds div Gleam@denominator
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 243).
-spec as_months_imprecise_fractional(integer()) -> float().
as_months_imprecise_fractional(Nanoseconds) ->
case erlang:float(2592000000000000) of
+0.0 -> +0.0;
-0.0 -> -0.0;
Gleam@denominator -> erlang:float(Nanoseconds) / Gleam@denominator
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 199).
-spec imprecise_weeks(integer()) -> integer().
imprecise_weeks(Weeks) ->
Weeks * 604800000000000.
-file("/home/john/tempo/src/gtempo/internal.gleam", 247).
-spec as_weeks_imprecise(integer()) -> integer().
as_weeks_imprecise(Nanoseconds) ->
case 604800000000000 of
0 -> 0;
Gleam@denominator -> Nanoseconds div Gleam@denominator
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 251).
-spec as_weeks_imprecise_fractional(integer()) -> float().
as_weeks_imprecise_fractional(Nanoseconds) ->
case erlang:float(604800000000000) of
+0.0 -> +0.0;
-0.0 -> -0.0;
Gleam@denominator -> erlang:float(Nanoseconds) / Gleam@denominator
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 203).
-spec imprecise_days(integer()) -> integer().
imprecise_days(Days) ->
Days * 86400000000000.
-file("/home/john/tempo/src/gtempo/internal.gleam", 255).
-spec as_days_imprecise(integer()) -> integer().
as_days_imprecise(Nanoseconds) ->
case 86400000000000 of
0 -> 0;
Gleam@denominator -> Nanoseconds div Gleam@denominator
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 259).
-spec as_days_fractional(integer()) -> float().
as_days_fractional(Nanoseconds) ->
case erlang:float(86400000000000) of
+0.0 -> +0.0;
-0.0 -> -0.0;
Gleam@denominator -> erlang:float(Nanoseconds) / Gleam@denominator
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 207).
-spec hours(integer()) -> integer().
hours(Hours) ->
Hours * 3600000000000.
-file("/home/john/tempo/src/gtempo/internal.gleam", 263).
-spec as_hours(integer()) -> integer().
as_hours(Nanoseconds) ->
case 3600000000000 of
0 -> 0;
Gleam@denominator -> Nanoseconds div Gleam@denominator
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 267).
-spec as_hours_fractional(integer()) -> float().
as_hours_fractional(Nanoseconds) ->
case erlang:float(3600000000000) of
+0.0 -> +0.0;
-0.0 -> -0.0;
Gleam@denominator -> erlang:float(Nanoseconds) / Gleam@denominator
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 211).
-spec minutes(integer()) -> integer().
minutes(Minutes) ->
Minutes * 60000000000.
-file("/home/john/tempo/src/gtempo/internal.gleam", 271).
-spec as_minutes(integer()) -> integer().
as_minutes(Nanoseconds) ->
case 60000000000 of
0 -> 0;
Gleam@denominator -> Nanoseconds div Gleam@denominator
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 275).
-spec as_minutes_fractional(integer()) -> float().
as_minutes_fractional(Nanoseconds) ->
case erlang:float(60000000000) of
+0.0 -> +0.0;
-0.0 -> -0.0;
Gleam@denominator -> erlang:float(Nanoseconds) / Gleam@denominator
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 215).
-spec seconds(integer()) -> integer().
seconds(Seconds) ->
Seconds * 1000000000.
-file("/home/john/tempo/src/gtempo/internal.gleam", 279).
-spec as_seconds(integer()) -> integer().
as_seconds(Nanoseconds) ->
case 1000000000 of
0 -> 0;
Gleam@denominator -> Nanoseconds div Gleam@denominator
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 283).
-spec as_seconds_fractional(integer()) -> float().
as_seconds_fractional(Nanoseconds) ->
case erlang:float(1000000000) of
+0.0 -> +0.0;
-0.0 -> -0.0;
Gleam@denominator -> erlang:float(Nanoseconds) / Gleam@denominator
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 219).
-spec milliseconds(integer()) -> integer().
milliseconds(Milliseconds) ->
Milliseconds * 1000000.
-file("/home/john/tempo/src/gtempo/internal.gleam", 287).
-spec as_milliseconds(integer()) -> integer().
as_milliseconds(Nanoseconds) ->
case 1000000 of
0 -> 0;
Gleam@denominator -> Nanoseconds div Gleam@denominator
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 291).
-spec as_milliseconds_fractional(integer()) -> float().
as_milliseconds_fractional(Nanoseconds) ->
case erlang:float(1000000) of
+0.0 -> +0.0;
-0.0 -> -0.0;
Gleam@denominator -> erlang:float(Nanoseconds) / Gleam@denominator
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 137).
-spec in_nanoseconds(unit()) -> integer().
in_nanoseconds(Unit) ->
case Unit of
year ->
31449600000000000;
month ->
2592000000000000;
week ->
604800000000000;
day ->
86400000000000;
{calculated_year, _, Nanoseconds} ->
Nanoseconds;
{calculated_month, _, Nanoseconds@1} ->
Nanoseconds@1;
hour ->
3600000000000;
minute ->
60000000000;
second ->
1000000000;
millisecond ->
1000000;
microsecond ->
1000;
nanosecond ->
1;
nothing ->
0
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 223).
-spec microseconds(integer()) -> integer().
microseconds(Microseconds) ->
Microseconds * 1000.
-file("/home/john/tempo/src/gtempo/internal.gleam", 295).
-spec as_microseconds(integer()) -> integer().
as_microseconds(Nanoseconds) ->
case 1000 of
0 -> 0;
Gleam@denominator -> Nanoseconds div Gleam@denominator
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 155).
-spec as_unit(integer(), unit()) -> integer().
as_unit(Nanoseconds, Unit) ->
case Unit of
year ->
as_years_imprecise(Nanoseconds);
{calculated_year, Years, _} ->
Years;
month ->
as_months_imprecise(Nanoseconds);
{calculated_month, Months, _} ->
Months;
week ->
as_weeks_imprecise(Nanoseconds);
day ->
as_days_imprecise(Nanoseconds);
hour ->
as_hours(Nanoseconds);
minute ->
as_minutes(Nanoseconds);
second ->
as_seconds(Nanoseconds);
millisecond ->
as_milliseconds(Nanoseconds);
microsecond ->
as_microseconds(Nanoseconds);
nanosecond ->
as_nanoseconds(Nanoseconds);
nothing ->
0
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 299).
-spec as_microseconds_fractional(integer()) -> float().
as_microseconds_fractional(Nanoseconds) ->
case erlang:float(1000) of
+0.0 -> +0.0;
-0.0 -> -0.0;
Gleam@denominator -> erlang:float(Nanoseconds) / Gleam@denominator
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 173).
-spec as_unit_fractional(integer(), unit()) -> float().
as_unit_fractional(Nanoseconds, Unit) ->
case Unit of
year ->
as_years_imprecise_fractional(Nanoseconds);
{calculated_year, Years, _} ->
_pipe = Years,
erlang:float(_pipe);
month ->
as_months_imprecise_fractional(Nanoseconds);
{calculated_month, Months, _} ->
_pipe@1 = Months,
erlang:float(_pipe@1);
week ->
as_weeks_imprecise_fractional(Nanoseconds);
day ->
as_days_fractional(Nanoseconds);
hour ->
as_hours_fractional(Nanoseconds);
minute ->
as_minutes_fractional(Nanoseconds);
second ->
as_seconds_fractional(Nanoseconds);
millisecond ->
as_milliseconds_fractional(Nanoseconds);
microsecond ->
as_microseconds_fractional(Nanoseconds);
nanosecond ->
_pipe@2 = as_nanoseconds(Nanoseconds),
erlang:float(_pipe@2);
nothing ->
+0.0
end.
-file("/home/john/tempo/src/gtempo/internal.gleam", 42).
-spec format_as(integer(), unit(), integer()) -> binary().
format_as(Nanoseconds, Unit, Decimals) ->
In_unit = as_unit_fractional(Nanoseconds, 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("/home/john/tempo/src/gtempo/internal.gleam", 78).
-spec format_as_many(integer(), list(unit()), integer()) -> binary().
format_as_many(Nanoseconds, Units, Decimals) ->
erlang:element(
2,
gleam@list:index_fold(
Units,
{Nanoseconds, <<""/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_nanoseconds(Unit) of
0 -> 0;
Gleam@denominator -> Nanoseconds 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
)
).