-module(tempo). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([instant_as_unix_utc/1, instant_as_unix_milli_utc/1, instant_compare/2, instant_is_earlier/2, instant_is_earlier_or_equal/2, instant_is_equal/2, instant_is_later/2, instant_is_later_or_equal/2, instant_difference/2, datetime/3, datetime_get_naive/1, datetime_get_offset/1, datetime_get_tz/1, datetime_drop_offset/1, naive_datetime/2, naive_datetime_get_date/1, naive_datetime_get_time/1, naive_datetime_set_offset/2, offset/1, offset_get_minutes/1, offset_to_string/1, validate_offset/1, new_offset/1, offset_to_duration/1, date/3, date_get_year/1, date_get_month/1, date_get_month_year/1, date_get_day/1, month_from_int/1, date_from_unix_seconds/1, instant_as_utc_date/1, instant_as_local_date/1, date_from_unix_micro/1, month_from_short_string/1, month_from_long_string/1, month_to_int/1, datetime_serialize/1, date_to_string/1, date_compare/2, date_is_earlier/2, date_is_earlier_or_equal/2, date_is_equal/2, date_is_later/2, date_is_later_or_equal/2, month_to_short_string/1, month_to_long_string/1, month_year_to_int/1, month_year_prior/1, month_year_next/1, is_leap_year/1, date_to_day_of_week_number/1, date_replace_format/2, date_to_unix_seconds/1, date_to_unix_micro/1, month_year_days_of/1, date_subtract/2, month_days_of/2, date_from_tuple/1, new_date/3, date_add/2, year_days/1, date_days_apart/2, time/4, time_get_hour/1, time_get_minute/1, time_get_second/1, time_get_micro/1, time_to_string/1, naive_datetime_to_string/1, datetime_to_string/1, validate_time/1, new_time/3, new_time_milli/4, new_time_micro/4, time_replace_format/2, adjust_12_hour_to_24_hour/2, time_to_microseconds/1, time_difference/2, time_from_microseconds/1, time_from_unix_micro/1, instant_as_utc_time/1, instant_as_local_time/1, instant_as_local_datetime/1, instant_to_local_string/1, time_to_duration/1, time_compare/2, naive_datetime_compare/2, naive_datetime_is_earlier/2, naive_datetime_is_earlier_or_equal/2, naive_datetime_is_later_or_equal/2, time_is_earlier/2, time_is_earlier_or_equal/2, time_is_equal/2, time_is_later/2, time_is_later_or_equal/2, time_add/2, time_subtract/2, duration/1, duration_get_microseconds/1, duration_days/1, duration_increase/2, naive_datetime_difference/2, duration_decrease/2, duration_absolute/1, duration_as_days/1, duration_as_microseconds/1, period_new_naive/2, period_new_date/2, period_get_start_and_end_date_and_time/1, period_as_duration/1, period_contains_naive_datetime/2, period_comprising_dates/1, period_comprising_months/1, get_datetime_format_str/1, get_naive_datetime_format_str/1, get_time_format_str/1, get_date_format_str/1, find_date/1, find_time/1, now_utc_ffi/0, now_monotonic_ffi/0, now_unique_ffi/0, offset_local_minutes/0, offset_local_micro/0, now/0, instant_since/1, instant_since_formatted/1, compare_utc_date/1, compare_local_date/1, is_utc_date_earlier/1, is_local_date_earlier/1, is_utc_date_earlier_or_equal/1, is_local_date_earlier_or_equal/1, is_utc_date_equal/1, is_local_date_equal/1, is_utc_date_later/1, is_local_date_later/1, is_utc_date_later_or_equal/1, is_local_date_later_or_equal/1, compare_utc_time/1, compare_local_time/1, is_utc_time_earlier/1, is_local_time_earlier/1, is_utc_time_earlier_or_equal/1, is_local_time_earlier_or_equal/1, is_utc_time_equal/1, is_local_time_equal/1, is_utc_time_later/1, is_local_time_later/1, is_utc_time_later_or_equal/1, is_local_time_later_or_equal/1, utc_time_difference_from/1, local_time_difference_from/1, utc_time_since/1, local_time_since/1, utc_time_until/1, local_time_until/1, utc_date_difference_from/1, local_date_difference_from/1, utc_days_since/1, local_days_since/1, utc_days_until/1, local_days_until/1, consume_format/2, now_adjusted/1, instant_as_utc_datetime/1, instant_to_utc_string/1, offset_from_string/1, parse_any/1, find_offset/1, datetime_format/2, format_utc/1, format_local/1, datetime_subtract/2, datetime_to_offset/2, naive_datetime_subtract/2, naive_datetime_add/2, datetime_apply_offset/1, datetime_to_utc/1, datetime_to_tz/2, datetime_compare/2, compare/1, datetime_is_earlier/2, is_earlier/1, datetime_is_earlier_or_equal/2, is_earlier_or_equal/1, datetime_is_equal/2, is_equal/1, datetime_is_later_or_equal/2, is_later_or_equal/1, datetime_is_later/2, is_later/1, datetime_difference/2, difference/1, since/1, until/1, datetime_add/2, period_new/2, period_contains_datetime/2]). -export_type([instant/0, date_time/0, time_zone_provider/0, naive_date_time/0, offset/0, date/0, month/0, month_year/0, time/0, duration/0, period/0, date_time_format/0, naive_date_time_format/0, date_format/0, time_format/0, locale/0, datetime_part/0]). -opaque instant() :: {instant, integer(), integer(), integer(), integer()}. -type date_time() :: {date_time, date(), time(), offset()} | {local_date_time, date(), time(), offset(), time_zone_provider()}. -type time_zone_provider() :: {time_zone_provider, fun(() -> binary()), fun((naive_date_time()) -> offset())}. -type naive_date_time() :: {naive_date_time, date(), time()}. -opaque offset() :: {offset, integer()}. -opaque date() :: {date, integer(), month(), integer()}. -type month() :: jan | feb | mar | apr | may | jun | jul | aug | sep | oct | nov | dec. -type month_year() :: {month_year, month(), integer()}. -opaque time() :: {time, integer(), integer(), integer(), integer()}. -opaque duration() :: {duration, integer()}. -opaque period() :: {date_time_period, date_time(), date_time()} | {naive_date_time_period, naive_date_time(), naive_date_time()} | {date_period, date(), date()}. -type date_time_format() :: iso8601_seconds | iso8601_milli | iso8601_micro | http | {custom, binary()} | {custom_localised, binary(), locale()} | {date_format, date_format()} | {time_format, time_format()}. -type naive_date_time_format() :: naive_iso8601_seconds | naive_iso8601_milli | naive_iso8601_micro | {custom_naive, binary()} | {custom_naive_localised, binary(), locale()} | {naive_date_format, date_format()} | {naive_time_format, time_format()}. -type date_format() :: iso8601_date | {custom_date, binary()} | {custom_date_localised, binary(), locale()}. -type time_format() :: iso8601_time | iso8601_time_milli | iso8601_time_micro | {custom_time, binary()} | {custom_time_localised, binary(), locale()}. -type locale() :: any(). -type datetime_part() :: {year, integer()} | {month, integer()} | {day, integer()} | {hour, integer()} | {minute, integer()} | {second, integer()} | {millisecond, integer()} | {microsecond, integer()} | {offset_str, binary()} | {twelve_hour, integer()} | am_period | pm_period | passthrough. -file("/home/john/Repos/tempo/src/tempo.gleam", 814). -spec instant_as_unix_utc(instant()) -> integer(). instant_as_unix_utc(Instant) -> erlang:element(3, Instant) div 1000000. -file("/home/john/Repos/tempo/src/tempo.gleam", 819). -spec instant_as_unix_milli_utc(instant()) -> integer(). instant_as_unix_milli_utc(Instant) -> erlang:element(3, Instant) div 1000. -file("/home/john/Repos/tempo/src/tempo.gleam", 856). -spec instant_compare(instant(), instant()) -> gleam@order:order(). instant_compare(A, B) -> gleam@int:compare(erlang:element(5, A), erlang:element(5, B)). -file("/home/john/Repos/tempo/src/tempo.gleam", 861). -spec instant_is_earlier(instant(), instant()) -> boolean(). instant_is_earlier(A, B) -> instant_compare(A, B) =:= lt. -file("/home/john/Repos/tempo/src/tempo.gleam", 866). -spec instant_is_earlier_or_equal(instant(), instant()) -> boolean(). instant_is_earlier_or_equal(A, B) -> (instant_compare(A, B) =:= lt) orelse (instant_compare(A, B) =:= eq). -file("/home/john/Repos/tempo/src/tempo.gleam", 871). -spec instant_is_equal(instant(), instant()) -> boolean(). instant_is_equal(A, B) -> instant_compare(A, B) =:= eq. -file("/home/john/Repos/tempo/src/tempo.gleam", 876). -spec instant_is_later(instant(), instant()) -> boolean(). instant_is_later(A, B) -> instant_compare(A, B) =:= gt. -file("/home/john/Repos/tempo/src/tempo.gleam", 881). -spec instant_is_later_or_equal(instant(), instant()) -> boolean(). instant_is_later_or_equal(A, B) -> (instant_compare(A, B) =:= gt) orelse (instant_compare(A, B) =:= eq). -file("/home/john/Repos/tempo/src/tempo.gleam", 886). -spec instant_difference(instant(), instant()) -> duration(). instant_difference(A, B) -> {duration, erlang:element(4, B) - erlang:element(4, A)}. -file("/home/john/Repos/tempo/src/tempo.gleam", 913). -spec datetime(date(), time(), offset()) -> date_time(). datetime(Date, Time, Offset) -> {date_time, Date, Time, Offset}. -file("/home/john/Repos/tempo/src/tempo.gleam", 918). -spec datetime_get_naive(date_time()) -> naive_date_time(). datetime_get_naive(Datetime) -> {naive_date_time, erlang:element(2, Datetime), erlang:element(3, Datetime)}. -file("/home/john/Repos/tempo/src/tempo.gleam", 923). -spec datetime_get_offset(date_time()) -> offset(). datetime_get_offset(Datetime) -> erlang:element(4, Datetime). -file("/home/john/Repos/tempo/src/tempo.gleam", 957). -spec datetime_get_tz(date_time()) -> gleam@option:option(binary()). datetime_get_tz(Datetime) -> case Datetime of {date_time, _, _, _} -> none; {local_date_time, _, _, _, Tz} -> {some, (erlang:element(2, Tz))()} end. -file("/home/john/Repos/tempo/src/tempo.gleam", 1091). -spec datetime_drop_offset(date_time()) -> naive_date_time(). datetime_drop_offset(Datetime) -> {naive_date_time, erlang:element(2, Datetime), erlang:element(3, Datetime)}. -file("/home/john/Repos/tempo/src/tempo.gleam", 1170). -spec naive_datetime(date(), time()) -> naive_date_time(). naive_datetime(Date, Time) -> {naive_date_time, Date, Time}. -file("/home/john/Repos/tempo/src/tempo.gleam", 1175). -spec naive_datetime_get_date(naive_date_time()) -> date(). naive_datetime_get_date(Naive_datetime) -> erlang:element(2, Naive_datetime). -file("/home/john/Repos/tempo/src/tempo.gleam", 1180). -spec naive_datetime_get_time(naive_date_time()) -> time(). naive_datetime_get_time(Naive_datetime) -> erlang:element(3, Naive_datetime). -file("/home/john/Repos/tempo/src/tempo.gleam", 1185). -spec naive_datetime_set_offset(naive_date_time(), offset()) -> date_time(). naive_datetime_set_offset(Naive, Offset) -> {date_time, erlang:element(2, Naive), erlang:element(3, Naive), Offset}. -file("/home/john/Repos/tempo/src/tempo.gleam", 1350). -spec offset(integer()) -> offset(). offset(Minutes) -> {offset, Minutes}. -file("/home/john/Repos/tempo/src/tempo.gleam", 1355). -spec offset_get_minutes(offset()) -> integer(). offset_get_minutes(Offset) -> erlang:element(2, Offset). -file("/home/john/Repos/tempo/src/tempo.gleam", 1431). -spec offset_to_string(offset()) -> binary(). offset_to_string(Offset) -> {Is_negative, Hours} = case offset_get_minutes(Offset) div 60 of H when H =< 0 -> {true, - H}; H@1 -> {false, H@1} end, Mins = case offset_get_minutes(Offset) rem 60 of M when M < 0 -> - M; M@1 -> M@1 end, case {Is_negative, Hours, Mins} of {_, 0, 0} -> <<"-00:00"/utf8>>; {_, 0, M@2} -> <<"-00:"/utf8, (begin _pipe = erlang:integer_to_binary(M@2), gleam@string:pad_start(_pipe, 2, <<"0"/utf8>>) end)/binary>>; {true, H@2, M@3} -> <<<<<<"-"/utf8, (begin _pipe@1 = erlang:integer_to_binary(H@2), gleam@string:pad_start(_pipe@1, 2, <<"0"/utf8>>) end)/binary>>/binary, ":"/utf8>>/binary, (begin _pipe@2 = erlang:integer_to_binary(M@3), gleam@string:pad_start(_pipe@2, 2, <<"0"/utf8>>) end)/binary>>; {false, H@3, M@4} -> <<<<<<"+"/utf8, (begin _pipe@3 = erlang:integer_to_binary(H@3), gleam@string:pad_start(_pipe@3, 2, <<"0"/utf8>>) end)/binary>>/binary, ":"/utf8>>/binary, (begin _pipe@4 = erlang:integer_to_binary(M@4), gleam@string:pad_start(_pipe@4, 2, <<"0"/utf8>>) end)/binary>> end. -file("/home/john/Repos/tempo/src/tempo.gleam", 1462). -spec validate_offset(offset()) -> {ok, offset()} | {error, nil}. validate_offset(Offset) -> case (erlang:element(2, Offset) >= -720) andalso (erlang:element(2, Offset) =< 840) of true -> {ok, Offset}; false -> {error, nil} end. -file("/home/john/Repos/tempo/src/tempo.gleam", 1363). -spec new_offset(integer()) -> {ok, offset()} | {error, nil}. new_offset(Minutes) -> _pipe = {offset, Minutes}, validate_offset(_pipe). -file("/home/john/Repos/tempo/src/tempo.gleam", 1471). -spec offset_to_duration(offset()) -> duration(). offset_to_duration(Offset) -> _pipe = - erlang:element(2, Offset) * 60000000, {duration, _pipe}. -file("/home/john/Repos/tempo/src/tempo.gleam", 1475). -spec offset_replace_format(binary(), offset()) -> binary(). offset_replace_format(Content, Offset) -> case Content of <<"z"/utf8>> -> case erlang:element(2, Offset) of 0 -> <<"Z"/utf8>>; _ -> Str_offset = begin _pipe = Offset, offset_to_string(_pipe) end, case begin _pipe@1 = Str_offset, gleam@string:split(_pipe@1, <<":"/utf8>>) end of [Hours, <<"00"/utf8>>] -> Hours; _ -> Str_offset end end; <<"zz"/utf8>> -> case erlang:element(2, Offset) of 0 -> <<"Z"/utf8>>; _ -> _pipe@2 = Offset, offset_to_string(_pipe@2) end; <<"Z"/utf8>> -> _pipe@3 = Offset, offset_to_string(_pipe@3); <<"ZZ"/utf8>> -> _pipe@4 = Offset, _pipe@5 = offset_to_string(_pipe@4), gleam@string:replace(_pipe@5, <<":"/utf8>>, <<""/utf8>>); _ -> Content end. -file("/home/john/Repos/tempo/src/tempo.gleam", 1514). -spec date(integer(), month(), integer()) -> date(). date(Year, Month, Day) -> {date, Year, Month, Day}. -file("/home/john/Repos/tempo/src/tempo.gleam", 1519). -spec date_get_year(date()) -> integer(). date_get_year(Date) -> erlang:element(2, Date). -file("/home/john/Repos/tempo/src/tempo.gleam", 1524). -spec date_get_month(date()) -> month(). date_get_month(Date) -> erlang:element(3, Date). -file("/home/john/Repos/tempo/src/tempo.gleam", 1529). -spec date_get_month_year(date()) -> month_year(). date_get_month_year(Date) -> {month_year, erlang:element(3, Date), erlang:element(2, Date)}. -file("/home/john/Repos/tempo/src/tempo.gleam", 1534). -spec date_get_day(date()) -> integer(). date_get_day(Date) -> erlang:element(4, Date). -file("/home/john/Repos/tempo/src/tempo.gleam", 1938). -spec calendar_years_apart(date(), date()) -> integer(). calendar_years_apart(Later, Earlier) -> erlang:element(2, Later) - erlang:element(2, Earlier). -file("/home/john/Repos/tempo/src/tempo.gleam", 2011). -spec month_from_int(integer()) -> {ok, month()} | {error, nil}. month_from_int(Month) -> case Month of 1 -> {ok, jan}; 2 -> {ok, feb}; 3 -> {ok, mar}; 4 -> {ok, apr}; 5 -> {ok, may}; 6 -> {ok, jun}; 7 -> {ok, jul}; 8 -> {ok, aug}; 9 -> {ok, sep}; 10 -> {ok, oct}; 11 -> {ok, nov}; 12 -> {ok, dec}; _ -> {error, nil} end. -file("/home/john/Repos/tempo/src/tempo.gleam", 1709). -spec date_from_unix_seconds(integer()) -> date(). date_from_unix_seconds(Unix_ts) -> Z = (Unix_ts div 86400) + 719468, Era = case Z >= 0 of true -> Z; false -> Z - 146096 end div 146097, Doe = Z - (Era * 146097), Yoe = (((Doe - (Doe div 1460)) + (Doe div 36524)) - (Doe div 146096)) div 365, Y = Yoe + (Era * 400), Doy = Doe - (((365 * Yoe) + (Yoe div 4)) - (Yoe div 100)), Mp = ((5 * Doy) + 2) div 153, D = (Doy - (((153 * Mp) + 2) div 5)) + 1, M = Mp + case Mp < 10 of true -> 3; false -> -9 end, Y@1 = case M =< 2 of true -> Y + 1; false -> Y end, _assert_subject = month_from_int(M), {ok, Month} = 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"/utf8>>, function => <<"date_from_unix_seconds"/utf8>>, line => 1734}) end, {date, Y@1, Month, D}. -file("/home/john/Repos/tempo/src/tempo.gleam", 834). -spec instant_as_utc_date(instant()) -> date(). instant_as_utc_date(Instant) -> date_from_unix_seconds(erlang:element(2, Instant) div 1000000). -file("/home/john/Repos/tempo/src/tempo.gleam", 839). -spec instant_as_local_date(instant()) -> date(). instant_as_local_date(Instant) -> date_from_unix_seconds( (erlang:element(2, Instant) + erlang:element(3, Instant)) div 1000000 ). -file("/home/john/Repos/tempo/src/tempo.gleam", 1782). -spec date_from_unix_micro(integer()) -> date(). date_from_unix_micro(Unix_ts) -> date_from_unix_seconds(Unix_ts div 1000000). -file("/home/john/Repos/tempo/src/tempo.gleam", 2030). -spec month_from_short_string(binary()) -> {ok, month()} | {error, nil}. month_from_short_string(Month) -> case Month of <<"Jan"/utf8>> -> {ok, jan}; <<"Feb"/utf8>> -> {ok, feb}; <<"Mar"/utf8>> -> {ok, mar}; <<"Apr"/utf8>> -> {ok, apr}; <<"May"/utf8>> -> {ok, may}; <<"Jun"/utf8>> -> {ok, jun}; <<"Jul"/utf8>> -> {ok, jul}; <<"Aug"/utf8>> -> {ok, aug}; <<"Sep"/utf8>> -> {ok, sep}; <<"Oct"/utf8>> -> {ok, oct}; <<"Nov"/utf8>> -> {ok, nov}; <<"Dec"/utf8>> -> {ok, dec}; _ -> {error, nil} end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2049). -spec month_from_long_string(binary()) -> {ok, month()} | {error, nil}. month_from_long_string(Month) -> case Month of <<"January"/utf8>> -> {ok, jan}; <<"February"/utf8>> -> {ok, feb}; <<"March"/utf8>> -> {ok, mar}; <<"April"/utf8>> -> {ok, apr}; <<"May"/utf8>> -> {ok, may}; <<"June"/utf8>> -> {ok, jun}; <<"July"/utf8>> -> {ok, jul}; <<"August"/utf8>> -> {ok, aug}; <<"September"/utf8>> -> {ok, sep}; <<"October"/utf8>> -> {ok, oct}; <<"November"/utf8>> -> {ok, nov}; <<"December"/utf8>> -> {ok, dec}; _ -> {error, nil} end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2068). -spec month_to_int(month()) -> integer(). month_to_int(Month) -> case Month of jan -> 1; feb -> 2; mar -> 3; apr -> 4; may -> 5; jun -> 6; jul -> 7; aug -> 8; sep -> 9; oct -> 10; nov -> 11; dec -> 12 end. -file("/home/john/Repos/tempo/src/tempo.gleam", 976). -spec datetime_serialize(date_time()) -> binary(). datetime_serialize(Datetime) -> D = erlang:element(2, Datetime), T = erlang:element(3, Datetime), O = erlang:element(4, Datetime), _pipe@18 = gleam_stdlib:identity( [begin _pipe = erlang:element(2, D), _pipe@1 = erlang:integer_to_binary(_pipe), gleam@string:pad_start(_pipe@1, 4, <<"0"/utf8>>) end, begin _pipe@2 = erlang:element(3, D), _pipe@3 = month_to_int(_pipe@2), _pipe@4 = erlang:integer_to_binary(_pipe@3), gleam@string:pad_start(_pipe@4, 2, <<"0"/utf8>>) end, begin _pipe@5 = erlang:element(4, D), _pipe@6 = erlang:integer_to_binary(_pipe@5), gleam@string:pad_start(_pipe@6, 2, <<"0"/utf8>>) end, <<"T"/utf8>>, begin _pipe@7 = erlang:element(2, T), _pipe@8 = erlang:integer_to_binary(_pipe@7), gleam@string:pad_start(_pipe@8, 2, <<"0"/utf8>>) end, begin _pipe@9 = erlang:element(3, T), _pipe@10 = erlang:integer_to_binary(_pipe@9), gleam@string:pad_start(_pipe@10, 2, <<"0"/utf8>>) end, begin _pipe@11 = erlang:element(4, T), _pipe@12 = erlang:integer_to_binary(_pipe@11), gleam@string:pad_start(_pipe@12, 2, <<"0"/utf8>>) end, <<"."/utf8>>, begin _pipe@13 = erlang:element(5, T), _pipe@14 = erlang:integer_to_binary(_pipe@13), gleam@string:pad_start(_pipe@14, 6, <<"0"/utf8>>) end, case begin _pipe@15 = O, offset_get_minutes(_pipe@15) end of 0 -> <<"Z"/utf8>>; _ -> Str_offset = begin _pipe@16 = O, offset_to_string(_pipe@16) end, case begin _pipe@17 = Str_offset, gleam@string:split(_pipe@17, <<":"/utf8>>) end of [Hours, <<"00"/utf8>>] -> Hours; _ -> Str_offset end end] ), unicode:characters_to_binary(_pipe@18). -file("/home/john/Repos/tempo/src/tempo.gleam", 1548). -spec date_to_string(date()) -> binary(). date_to_string(Date) -> _pipe@3 = gleam_stdlib:identity( [erlang:integer_to_binary(erlang:element(2, Date)), <<"-"/utf8>>, begin _pipe = month_to_int(erlang:element(3, Date)), _pipe@1 = erlang:integer_to_binary(_pipe), gleam@string:pad_start(_pipe@1, 2, <<"0"/utf8>>) end, <<"-"/utf8>>, begin _pipe@2 = erlang:integer_to_binary(erlang:element(4, Date)), gleam@string:pad_start(_pipe@2, 2, <<"0"/utf8>>) end] ), unicode:characters_to_binary(_pipe@3). -file("/home/john/Repos/tempo/src/tempo.gleam", 1943). -spec date_compare(date(), date()) -> gleam@order:order(). date_compare(A, B) -> case erlang:element(2, A) =:= erlang:element(2, B) of true -> case erlang:element(3, A) =:= erlang:element(3, B) of true -> case erlang:element(4, A) =:= erlang:element(4, B) of true -> eq; false -> gleam@int:compare( erlang:element(4, A), erlang:element(4, B) ) end; false -> gleam@int:compare( month_to_int( begin _pipe = A, date_get_month(_pipe) end ), month_to_int( begin _pipe@1 = B, date_get_month(_pipe@1) end ) ) end; false -> gleam@int:compare(erlang:element(2, A), erlang:element(2, B)) end. -file("/home/john/Repos/tempo/src/tempo.gleam", 1963). -spec date_is_earlier(date(), date()) -> boolean(). date_is_earlier(A, B) -> date_compare(A, B) =:= lt. -file("/home/john/Repos/tempo/src/tempo.gleam", 1968). -spec date_is_earlier_or_equal(date(), date()) -> boolean(). date_is_earlier_or_equal(A, B) -> (date_compare(A, B) =:= lt) orelse (date_compare(A, B) =:= eq). -file("/home/john/Repos/tempo/src/tempo.gleam", 1973). -spec date_is_equal(date(), date()) -> boolean(). date_is_equal(A, B) -> date_compare(A, B) =:= eq. -file("/home/john/Repos/tempo/src/tempo.gleam", 1978). -spec date_is_later(date(), date()) -> boolean(). date_is_later(A, B) -> date_compare(A, B) =:= gt. -file("/home/john/Repos/tempo/src/tempo.gleam", 1983). -spec date_is_later_or_equal(date(), date()) -> boolean(). date_is_later_or_equal(A, B) -> (date_compare(A, B) =:= gt) orelse (date_compare(A, B) =:= eq). -file("/home/john/Repos/tempo/src/tempo.gleam", 2086). -spec month_to_short_string(month()) -> binary(). month_to_short_string(Month) -> case Month of jan -> <<"Jan"/utf8>>; feb -> <<"Feb"/utf8>>; mar -> <<"Mar"/utf8>>; apr -> <<"Apr"/utf8>>; may -> <<"May"/utf8>>; jun -> <<"Jun"/utf8>>; jul -> <<"Jul"/utf8>>; aug -> <<"Aug"/utf8>>; sep -> <<"Sep"/utf8>>; oct -> <<"Oct"/utf8>>; nov -> <<"Nov"/utf8>>; dec -> <<"Dec"/utf8>> end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2104). -spec month_to_long_string(month()) -> binary(). month_to_long_string(Month) -> case Month of jan -> <<"January"/utf8>>; feb -> <<"February"/utf8>>; mar -> <<"March"/utf8>>; apr -> <<"April"/utf8>>; may -> <<"May"/utf8>>; jun -> <<"June"/utf8>>; jul -> <<"July"/utf8>>; aug -> <<"August"/utf8>>; sep -> <<"September"/utf8>>; oct -> <<"October"/utf8>>; nov -> <<"November"/utf8>>; dec -> <<"December"/utf8>> end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2136). -spec month_year_to_int(month_year()) -> integer(). month_year_to_int(Month_year) -> (erlang:element(3, Month_year) * 100) + month_to_int( erlang:element(2, Month_year) ). -file("/home/john/Repos/tempo/src/tempo.gleam", 2141). -spec month_year_prior(month_year()) -> month_year(). month_year_prior(Month_year) -> case erlang:element(2, Month_year) of jan -> {month_year, dec, erlang:element(3, Month_year) - 1}; feb -> {month_year, jan, erlang:element(3, Month_year)}; mar -> {month_year, feb, erlang:element(3, Month_year)}; apr -> {month_year, mar, erlang:element(3, Month_year)}; may -> {month_year, apr, erlang:element(3, Month_year)}; jun -> {month_year, may, erlang:element(3, Month_year)}; jul -> {month_year, jun, erlang:element(3, Month_year)}; aug -> {month_year, jul, erlang:element(3, Month_year)}; sep -> {month_year, aug, erlang:element(3, Month_year)}; oct -> {month_year, sep, erlang:element(3, Month_year)}; nov -> {month_year, oct, erlang:element(3, Month_year)}; dec -> {month_year, nov, erlang:element(3, Month_year)} end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2159). -spec month_year_next(month_year()) -> month_year(). month_year_next(Month_year) -> case erlang:element(2, Month_year) of jan -> {month_year, feb, erlang:element(3, Month_year)}; feb -> {month_year, mar, erlang:element(3, Month_year)}; mar -> {month_year, apr, erlang:element(3, Month_year)}; apr -> {month_year, may, erlang:element(3, Month_year)}; may -> {month_year, jun, erlang:element(3, Month_year)}; jun -> {month_year, jul, erlang:element(3, Month_year)}; jul -> {month_year, aug, erlang:element(3, Month_year)}; aug -> {month_year, sep, erlang:element(3, Month_year)}; sep -> {month_year, oct, erlang:element(3, Month_year)}; oct -> {month_year, nov, erlang:element(3, Month_year)}; nov -> {month_year, dec, erlang:element(3, Month_year)}; dec -> {month_year, jan, erlang:element(3, Month_year) + 1} end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2206). -spec is_leap_year(integer()) -> boolean(). is_leap_year(Year) -> case (Year rem 4) =:= 0 of true -> case (Year rem 100) =:= 0 of true -> case (Year rem 400) =:= 0 of true -> true; false -> false end; false -> true end; false -> false end. -file("/home/john/Repos/tempo/src/tempo.gleam", 1636). -spec date_to_day_of_week_number(date()) -> integer(). date_to_day_of_week_number(Date) -> Year_code = begin _pipe = erlang:element(2, Date) rem 100, (fun(Short_year) -> (Short_year + (Short_year div 4)) rem 7 end)(_pipe) end, Month_code = case erlang:element(3, Date) of jan -> 0; feb -> 3; mar -> 3; apr -> 6; may -> 1; jun -> 4; jul -> 6; aug -> 2; sep -> 5; oct -> 0; nov -> 3; dec -> 5 end, Century_code = case erlang:element(2, Date) of Year when Year < 1752 -> 0; Year@1 when Year@1 < 1800 -> 4; Year@2 when Year@2 < 1900 -> 2; Year@3 when Year@3 < 2000 -> 0; Year@4 when Year@4 < 2100 -> 6; Year@5 when Year@5 < 2200 -> 4; Year@6 when Year@6 < 2300 -> 2; Year@7 when Year@7 < 2400 -> 4; _ -> 0 end, Leap_year_code = case is_leap_year(erlang:element(2, Date)) of true -> case erlang:element(3, Date) of jan -> 1; feb -> 1; _ -> 0 end; false -> 0 end, ((((Year_code + Month_code) + Century_code) + erlang:element(4, Date)) - Leap_year_code) rem 7. -file("/home/john/Repos/tempo/src/tempo.gleam", 1609). -spec date_to_day_of_week_short(date()) -> binary(). date_to_day_of_week_short(Date) -> case date_to_day_of_week_number(Date) of 0 -> <<"Sun"/utf8>>; 1 -> <<"Mon"/utf8>>; 2 -> <<"Tue"/utf8>>; 3 -> <<"Wed"/utf8>>; 4 -> <<"Thu"/utf8>>; 5 -> <<"Fri"/utf8>>; 6 -> <<"Sat"/utf8>>; _ -> erlang:error(#{gleam_error => panic, message => <<"Invalid day of week found after modulo by 7"/utf8>>, module => <<"tempo"/utf8>>, function => <<"date_to_day_of_week_short"/utf8>>, line => 1618}) end. -file("/home/john/Repos/tempo/src/tempo.gleam", 1622). -spec date_to_day_of_week_long(date()) -> binary(). date_to_day_of_week_long(Date) -> case date_to_day_of_week_number(Date) of 0 -> <<"Sunday"/utf8>>; 1 -> <<"Monday"/utf8>>; 2 -> <<"Tuesday"/utf8>>; 3 -> <<"Wednesday"/utf8>>; 4 -> <<"Thursday"/utf8>>; 5 -> <<"Friday"/utf8>>; 6 -> <<"Saturday"/utf8>>; _ -> erlang:error(#{gleam_error => panic, message => <<"Invalid day of week found after modulo by 7"/utf8>>, module => <<"tempo"/utf8>>, function => <<"date_to_day_of_week_long"/utf8>>, line => 1631}) end. -file("/home/john/Repos/tempo/src/tempo.gleam", 1562). -spec date_replace_format(binary(), date()) -> binary(). date_replace_format(Content, Date) -> case Content of <<"YY"/utf8>> -> _pipe = erlang:element(2, Date), _pipe@1 = erlang:integer_to_binary(_pipe), _pipe@2 = gleam@string:pad_start(_pipe@1, 2, <<"0"/utf8>>), gleam@string:slice(_pipe@2, -2, 2); <<"YYYY"/utf8>> -> _pipe@3 = erlang:element(2, Date), _pipe@4 = erlang:integer_to_binary(_pipe@3), gleam@string:pad_start(_pipe@4, 4, <<"0"/utf8>>); <<"M"/utf8>> -> _pipe@5 = erlang:element(3, Date), _pipe@6 = month_to_int(_pipe@5), erlang:integer_to_binary(_pipe@6); <<"MM"/utf8>> -> _pipe@7 = erlang:element(3, Date), _pipe@8 = month_to_int(_pipe@7), _pipe@9 = erlang:integer_to_binary(_pipe@8), gleam@string:pad_start(_pipe@9, 2, <<"0"/utf8>>); <<"MMM"/utf8>> -> _pipe@10 = erlang:element(3, Date), month_to_short_string(_pipe@10); <<"MMMM"/utf8>> -> _pipe@11 = erlang:element(3, Date), month_to_long_string(_pipe@11); <<"D"/utf8>> -> _pipe@12 = erlang:element(4, Date), erlang:integer_to_binary(_pipe@12); <<"DD"/utf8>> -> _pipe@13 = erlang:element(4, Date), _pipe@14 = erlang:integer_to_binary(_pipe@13), gleam@string:pad_start(_pipe@14, 2, <<"0"/utf8>>); <<"d"/utf8>> -> _pipe@15 = Date, _pipe@16 = date_to_day_of_week_number(_pipe@15), erlang:integer_to_binary(_pipe@16); <<"dd"/utf8>> -> _pipe@17 = Date, _pipe@18 = date_to_day_of_week_short(_pipe@17), gleam@string:slice(_pipe@18, 0, 2); <<"ddd"/utf8>> -> _pipe@19 = Date, date_to_day_of_week_short(_pipe@19); <<"dddd"/utf8>> -> _pipe@20 = Date, date_to_day_of_week_long(_pipe@20); _ -> Content end. -file("/home/john/Repos/tempo/src/tempo.gleam", 1740). -spec date_to_unix_seconds(date()) -> integer(). date_to_unix_seconds(Date) -> Full_years_since_epoch = date_get_year(Date) - 1970, Full_elapsed_leap_years_since_epoch = (Full_years_since_epoch + 1) div 4, Full_elapsed_non_leap_years_since_epoch = Full_years_since_epoch - Full_elapsed_leap_years_since_epoch, Year_sec = (Full_elapsed_non_leap_years_since_epoch * 31536000) + (Full_elapsed_leap_years_since_epoch * 31622400), Feb_milli = case is_leap_year( begin _pipe = Date, date_get_year(_pipe) end ) of true -> 2505600; false -> 2419200 end, Month_sec = case begin _pipe@1 = Date, date_get_month(_pipe@1) end of jan -> 0; feb -> 2678400; mar -> 2678400 + Feb_milli; apr -> 5356800 + Feb_milli; may -> 7948800 + Feb_milli; jun -> 10627200 + Feb_milli; jul -> 13219200 + Feb_milli; aug -> 15897600 + Feb_milli; sep -> 18576000 + Feb_milli; oct -> 21168000 + Feb_milli; nov -> 23846400 + Feb_milli; dec -> 26438400 + Feb_milli end, Day_sec = (date_get_day(Date) - 1) * 86400, (Year_sec + Month_sec) + Day_sec. -file("/home/john/Repos/tempo/src/tempo.gleam", 1787). -spec date_to_unix_micro(date()) -> integer(). date_to_unix_micro(Date) -> date_to_unix_seconds(Date) * 1000000. -file("/home/john/Repos/tempo/src/tempo.gleam", 2177). -spec month_year_days_of(month_year()) -> integer(). month_year_days_of(My) -> case erlang:element(2, My) of jan -> 31; mar -> 31; may -> 31; jul -> 31; aug -> 31; oct -> 31; dec -> 31; _ -> case erlang:element(2, My) of apr -> 30; jun -> 30; sep -> 30; nov -> 30; _ -> case is_leap_year(erlang:element(3, My)) of true -> 29; false -> 28 end end end. -file("/home/john/Repos/tempo/src/tempo.gleam", 1808). -spec date_subtract(date(), integer()) -> date(). date_subtract(Date, Days) -> case Days < erlang:element(4, Date) of true -> {date, erlang:element(2, Date), erlang:element(3, Date), (erlang:element(4, Date)) - Days}; false -> Prior_month = month_year_prior( begin _pipe = Date, date_get_month_year(_pipe) end ), date_subtract( {date, erlang:element(3, Prior_month), erlang:element(2, Prior_month), month_year_days_of(Prior_month)}, Days - date_get_day(Date) ) end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2122). -spec month_days_of(month(), integer()) -> integer(). month_days_of(Month, Year) -> month_year_days_of({month_year, Month, Year}). -file("/home/john/Repos/tempo/src/tempo.gleam", 1681). -spec date_from_tuple({integer(), integer(), integer()}) -> {ok, date()} | {error, tempo@error:date_out_of_bounds_error()}. date_from_tuple(Date) -> Year = erlang:element(1, Date), Month = erlang:element(2, Date), Day = erlang:element(3, Date), gleam@result:'try'( begin _pipe = month_from_int(Month), gleam@result:replace_error( _pipe, {date_month_out_of_bounds, erlang:integer_to_binary(Month)} ) end, fun(Month@1) -> case (Year >= 1000) andalso (Year =< 9999) of true -> case (Day >= 1) andalso (Day =< month_days_of(Month@1, Year)) of true -> {ok, {date, Year, Month@1, Day}}; false -> {error, {date_day_out_of_bounds, <<<<(month_to_short_string(Month@1))/binary, " "/utf8>>/binary, (erlang:integer_to_binary(Day))/binary>>}} end; false -> {error, {date_year_out_of_bounds, erlang:integer_to_binary(Year)}} end end ). -file("/home/john/Repos/tempo/src/tempo.gleam", 1539). -spec new_date(integer(), integer(), integer()) -> {ok, date()} | {error, tempo@error:date_out_of_bounds_error()}. new_date(Year, Month, Day) -> date_from_tuple({Year, Month, Day}). -file("/home/john/Repos/tempo/src/tempo.gleam", 1792). -spec date_add(date(), integer()) -> date(). date_add(Date, Days) -> Days_left_this_month = month_days_of( erlang:element(3, Date), erlang:element(2, Date) ) - erlang:element(4, Date), case Days =< Days_left_this_month of true -> {date, erlang:element(2, Date), erlang:element(3, Date), (erlang:element(4, Date)) + Days}; false -> Next_month = month_year_next( begin _pipe = Date, date_get_month_year(_pipe) end ), date_add( {date, erlang:element(3, Next_month), erlang:element(2, Next_month), 1}, (Days - Days_left_this_month) - 1 ) end. -file("/home/john/Repos/tempo/src/tempo.gleam", 1879). -spec exclusive_months_between_days(date(), date()) -> integer(). exclusive_months_between_days(From, To) -> gleam@bool:guard( ((erlang:element(2, To) =:= erlang:element(2, From)) andalso (begin _pipe = month_year_prior( {month_year, erlang:element(3, To), erlang:element(2, To)} ), month_year_to_int(_pipe) end < begin _pipe@1 = month_year_next( {month_year, erlang:element(3, From), erlang:element(2, From)} ), month_year_to_int(_pipe@1) end)), 0, fun() -> _pipe@16 = case erlang:element(2, To) =:= erlang:element(2, From) of true -> _pipe@6 = gleam@list:range( month_to_int( erlang:element( 2, begin _pipe@2 = From, _pipe@3 = date_get_month_year(_pipe@2), month_year_next(_pipe@3) end ) ), month_to_int( erlang:element( 2, begin _pipe@4 = To, _pipe@5 = date_get_month_year(_pipe@4), month_year_prior(_pipe@5) end ) ) ), gleam@list:map( _pipe@6, fun(M) -> _assert_subject = month_from_int(M), {ok, M@1} = 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"/utf8>>, function => <<"exclusive_months_between_days"/utf8>>, line => 1898}) end, M@1 end ); false -> _pipe@10 = case begin _pipe@7 = To, date_get_month(_pipe@7) end =:= jan of true -> []; false -> gleam@list:range( 1, month_to_int( erlang:element( 2, begin _pipe@8 = To, _pipe@9 = date_get_month_year( _pipe@8 ), month_year_prior(_pipe@9) end ) ) ) end, _pipe@11 = gleam@list:map( _pipe@10, fun(M@2) -> _assert_subject@1 = month_from_int(M@2), {ok, M@3} = case _assert_subject@1 of {ok, _} -> _assert_subject@1; _assert_fail@1 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail@1, module => <<"tempo"/utf8>>, function => <<"exclusive_months_between_days"/utf8>>, line => 1913}) end, M@3 end ), lists:append( _pipe@11, begin _pipe@15 = case begin _pipe@12 = From, date_get_month(_pipe@12) end =:= dec of true -> []; false -> gleam@list:range( month_to_int( erlang:element( 2, begin _pipe@13 = From, _pipe@14 = date_get_month_year( _pipe@13 ), month_year_next(_pipe@14) end ) ), 12 ) end, gleam@list:map( _pipe@15, fun(M@4) -> _assert_subject@2 = month_from_int(M@4), {ok, M@5} = case _assert_subject@2 of {ok, _} -> _assert_subject@2; _assert_fail@2 -> erlang:error( #{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, value => _assert_fail@2, module => <<"tempo"/utf8>>, function => <<"exclusive_months_between_days"/utf8>>, line => 1928} ) end, M@5 end ) end ) end, _pipe@18 = gleam@list:map( _pipe@16, fun(M@6) -> month_days_of( M@6, begin _pipe@17 = To, date_get_year(_pipe@17) end ) end ), gleam@int:sum(_pipe@18) end ). -file("/home/john/Repos/tempo/src/tempo.gleam", 2222). -spec year_days(integer()) -> integer(). year_days(Year) -> case is_leap_year(Year) of true -> 366; false -> 365 end. -file("/home/john/Repos/tempo/src/tempo.gleam", 1836). -spec date_days_apart_positive(date(), date()) -> integer(). date_days_apart_positive(Start_date, End_date) -> Days_in_the_years_between = case calendar_years_apart(End_date, Start_date) of Years_apart when Years_apart >= 2 -> _pipe = gleam@list:range(1, Years_apart - 1), _pipe@2 = gleam@list:map( _pipe, fun(I) -> _pipe@1 = date_get_year(End_date) + I, year_days(_pipe@1) end ), gleam@int:sum(_pipe@2); _ -> 0 end, Days_in_the_months_between = exclusive_months_between_days( Start_date, End_date ), Days_apart = case (date_get_year(End_date) =:= date_get_year(Start_date)) andalso (begin _pipe@3 = date_get_month(End_date), month_to_int(_pipe@3) end =< begin _pipe@4 = date_get_month(Start_date), month_to_int(_pipe@4) end) of true -> date_get_day(End_date) - date_get_day(Start_date); false -> date_get_day(End_date) + (month_days_of( date_get_month(Start_date), date_get_year(Start_date) ) - date_get_day(Start_date)) end, (Days_in_the_years_between + Days_in_the_months_between) + Days_apart. -file("/home/john/Repos/tempo/src/tempo.gleam", 1827). -spec date_days_apart(date(), date()) -> integer(). date_days_apart(Start_date, End_date) -> case begin _pipe = Start_date, date_is_earlier_or_equal(_pipe, End_date) end of true -> date_days_apart_positive(Start_date, End_date); false -> - date_days_apart_positive(End_date, Start_date) end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2247). -spec time(integer(), integer(), integer(), integer()) -> time(). time(Hour, Minute, Second, Microsecond) -> {time, Hour, Minute, Second, Microsecond}. -file("/home/john/Repos/tempo/src/tempo.gleam", 2252). -spec time_get_hour(time()) -> integer(). time_get_hour(Time) -> erlang:element(2, Time). -file("/home/john/Repos/tempo/src/tempo.gleam", 2257). -spec time_get_minute(time()) -> integer(). time_get_minute(Time) -> erlang:element(3, Time). -file("/home/john/Repos/tempo/src/tempo.gleam", 2262). -spec time_get_second(time()) -> integer(). time_get_second(Time) -> erlang:element(4, Time). -file("/home/john/Repos/tempo/src/tempo.gleam", 2267). -spec time_get_micro(time()) -> integer(). time_get_micro(Time) -> erlang:element(5, Time). -file("/home/john/Repos/tempo/src/tempo.gleam", 2345). -spec time_to_string(time()) -> binary(). time_to_string(Time) -> _pipe@6 = gleam_stdlib:identity( [begin _pipe = erlang:element(2, Time), _pipe@1 = erlang:integer_to_binary(_pipe), gleam@string:pad_start(_pipe@1, 2, <<"0"/utf8>>) end, <<":"/utf8>>, begin _pipe@2 = erlang:element(3, Time), _pipe@3 = erlang:integer_to_binary(_pipe@2), gleam@string:pad_start(_pipe@3, 2, <<"0"/utf8>>) end, <<":"/utf8>>, begin _pipe@4 = erlang:element(4, Time), _pipe@5 = erlang:integer_to_binary(_pipe@4), gleam@string:pad_start(_pipe@5, 2, <<"0"/utf8>>) end] ), _pipe@7 = gleam@string_tree:append(_pipe@6, <<"."/utf8>>), _pipe@10 = gleam@string_tree:append( _pipe@7, begin _pipe@8 = erlang:element(5, Time), _pipe@9 = erlang:integer_to_binary(_pipe@8), gleam@string:pad_start(_pipe@9, 6, <<"0"/utf8>>) end ), unicode:characters_to_binary(_pipe@10). -file("/home/john/Repos/tempo/src/tempo.gleam", 1193). -spec naive_datetime_to_string(naive_date_time()) -> binary(). naive_datetime_to_string(Datetime) -> <<<<(begin _pipe = erlang:element(2, Datetime), date_to_string(_pipe) end)/binary, "T"/utf8>>/binary, (begin _pipe@1 = erlang:element(3, Datetime), time_to_string(_pipe@1) end)/binary>>. -file("/home/john/Repos/tempo/src/tempo.gleam", 965). -spec datetime_to_string(date_time()) -> binary(). datetime_to_string(Datetime) -> <<(begin _pipe = {naive_date_time, erlang:element(2, Datetime), erlang:element(3, Datetime)}, naive_datetime_to_string(_pipe) end)/binary, (case erlang:element(2, erlang:element(4, Datetime)) of 0 -> <<"Z"/utf8>>; _ -> _pipe@1 = erlang:element(4, Datetime), offset_to_string(_pipe@1) end)/binary>>. -file("/home/john/Repos/tempo/src/tempo.gleam", 2303). -spec validate_time(time()) -> {ok, time()} | {error, tempo@error:time_out_of_bounds_error()}. validate_time(Time) -> case (((((((erlang:element(2, Time) >= 0) andalso (erlang:element(2, Time) =< 23)) andalso (erlang:element(3, Time) >= 0)) andalso (erlang:element(3, Time) =< 59)) andalso (erlang:element(4, Time) >= 0)) andalso (erlang:element(4, Time) =< 59)) orelse ((((erlang:element(2, Time) =:= 24) andalso (erlang:element(3, Time) =:= 0)) andalso (erlang:element(4, Time) =:= 0)) andalso (erlang:element(5, Time) =:= 0))) orelse (((erlang:element(3, Time) =:= 59) andalso (erlang:element(4, Time) =:= 60)) andalso (erlang:element(5, Time) =:= 0)) of true -> case erlang:element(5, Time) =< 999999 of true -> {ok, Time}; false -> {error, {time_micro_second_out_of_bounds, time_to_string(Time)}} end; false -> case {erlang:element(2, Time), erlang:element(3, Time), erlang:element(4, Time)} of {_, _, S} when (S > 59) orelse (S < 0) -> {error, {time_second_out_of_bounds, time_to_string(Time)}}; {_, M, _} when (M > 59) orelse (M < 0) -> {error, {time_minute_out_of_bounds, time_to_string(Time)}}; {_, _, _} -> {error, {time_hour_out_of_bounds, time_to_string(Time)}} end end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2272). -spec new_time(integer(), integer(), integer()) -> {ok, time()} | {error, tempo@error:time_out_of_bounds_error()}. new_time(Hour, Minute, Second) -> _pipe = {time, Hour, Minute, Second, 0}, validate_time(_pipe). -file("/home/john/Repos/tempo/src/tempo.gleam", 2281). -spec new_time_milli(integer(), integer(), integer(), integer()) -> {ok, time()} | {error, tempo@error:time_out_of_bounds_error()}. new_time_milli(Hour, Minute, Second, Millisecond) -> _pipe = {time, Hour, Minute, Second, Millisecond * 1000}, validate_time(_pipe). -file("/home/john/Repos/tempo/src/tempo.gleam", 2292). -spec new_time_micro(integer(), integer(), integer(), integer()) -> {ok, time()} | {error, tempo@error:time_out_of_bounds_error()}. new_time_micro(Hour, Minute, Second, Microsecond) -> _pipe = {time, Hour, Minute, Second, Microsecond}, validate_time(_pipe). -file("/home/john/Repos/tempo/src/tempo.gleam", 2369). -spec time_replace_format(binary(), time()) -> binary(). time_replace_format(Content, Time) -> case Content of <<"H"/utf8>> -> _pipe = erlang:element(2, Time), erlang:integer_to_binary(_pipe); <<"HH"/utf8>> -> _pipe@1 = erlang:element(2, Time), _pipe@2 = erlang:integer_to_binary(_pipe@1), gleam@string:pad_start(_pipe@2, 2, <<"0"/utf8>>); <<"h"/utf8>> -> _pipe@3 = case erlang:element(2, Time) of Hour when Hour =:= 0 -> 12; Hour@1 when Hour@1 > 12 -> Hour@1 - 12; Hour@2 -> Hour@2 end, erlang:integer_to_binary(_pipe@3); <<"hh"/utf8>> -> _pipe@4 = case erlang:element(2, Time) of Hour@3 when Hour@3 =:= 0 -> 12; Hour@4 when Hour@4 > 12 -> Hour@4 - 12; Hour@5 -> Hour@5 end, _pipe@5 = erlang:integer_to_binary(_pipe@4), gleam@string:pad_start(_pipe@5, 2, <<"0"/utf8>>); <<"a"/utf8>> -> case erlang:element(2, Time) >= 12 of true -> <<"pm"/utf8>>; false -> <<"am"/utf8>> end; <<"A"/utf8>> -> case erlang:element(2, Time) >= 12 of true -> <<"PM"/utf8>>; false -> <<"AM"/utf8>> end; <<"m"/utf8>> -> _pipe@6 = erlang:element(3, Time), erlang:integer_to_binary(_pipe@6); <<"mm"/utf8>> -> _pipe@7 = erlang:element(3, Time), _pipe@8 = erlang:integer_to_binary(_pipe@7), gleam@string:pad_start(_pipe@8, 2, <<"0"/utf8>>); <<"s"/utf8>> -> _pipe@9 = erlang:element(4, Time), erlang:integer_to_binary(_pipe@9); <<"ss"/utf8>> -> _pipe@10 = erlang:element(4, Time), _pipe@11 = erlang:integer_to_binary(_pipe@10), gleam@string:pad_start(_pipe@11, 2, <<"0"/utf8>>); <<"SSS"/utf8>> -> _pipe@12 = (erlang:element(5, Time) div 1000), _pipe@13 = erlang:integer_to_binary(_pipe@12), gleam@string:pad_start(_pipe@13, 3, <<"0"/utf8>>); <<"SSSS"/utf8>> -> _pipe@14 = (erlang:element(5, Time)), _pipe@15 = erlang:integer_to_binary(_pipe@14), gleam@string:pad_start(_pipe@15, 6, <<"0"/utf8>>); _ -> Content end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2424). -spec adjust_12_hour_to_24_hour(integer(), boolean()) -> integer(). adjust_12_hour_to_24_hour(Hour, Am) -> case {Am, Hour} of {true, _} when Hour =:= 12 -> 0; {true, _} -> Hour; {false, _} when Hour =:= 12 -> Hour; {false, _} -> Hour + 12 end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2439). -spec time_to_microseconds(time()) -> integer(). time_to_microseconds(Time) -> (((erlang:element(2, Time) * 3600000000) + (erlang:element(3, Time) * 60000000)) + (erlang:element(4, Time) * 1000000)) + (erlang:element(5, Time)). -file("/home/john/Repos/tempo/src/tempo.gleam", 2434). -spec time_difference(time(), time()) -> duration(). time_difference(A, B) -> _pipe = time_to_microseconds(B) - time_to_microseconds(A), {duration, _pipe}. -file("/home/john/Repos/tempo/src/tempo.gleam", 2447). -spec time_from_microseconds(integer()) -> time(). time_from_microseconds(Microseconds) -> In_range_micro = case 86400000000 of 0 -> 0; Gleam@denominator -> Microseconds rem Gleam@denominator end, Adj_micro = case In_range_micro < 0 of true -> In_range_micro + 86400000000; false -> In_range_micro end, Hour = Adj_micro div 3600000000, Minute = (Adj_micro - (Hour * 3600000000)) div 60000000, Second = ((Adj_micro - (Hour * 3600000000)) - (Minute * 60000000)) div 1000000, Microsecond = ((Adj_micro - (Hour * 3600000000)) - (Minute * 60000000)) - (Second * 1000000), {time, Hour, Minute, Second, Microsecond}. -file("/home/john/Repos/tempo/src/tempo.gleam", 2469). -spec time_from_unix_micro(integer()) -> time(). time_from_unix_micro(Unix_ts) -> _pipe = (Unix_ts - (date_to_unix_micro(date_from_unix_micro(Unix_ts)))), time_from_microseconds(_pipe). -file("/home/john/Repos/tempo/src/tempo.gleam", 846). -spec instant_as_utc_time(instant()) -> time(). instant_as_utc_time(Instant) -> time_from_unix_micro(erlang:element(2, Instant)). -file("/home/john/Repos/tempo/src/tempo.gleam", 851). -spec instant_as_local_time(instant()) -> time(). instant_as_local_time(Instant) -> time_from_unix_micro( erlang:element(2, Instant) + erlang:element(3, Instant) ). -file("/home/john/Repos/tempo/src/tempo.gleam", 805). -spec instant_as_local_datetime(instant()) -> date_time(). instant_as_local_datetime(Instant) -> {date_time, instant_as_local_date(Instant), instant_as_local_time(Instant), {offset, erlang:element(3, Instant) div 60000000}}. -file("/home/john/Repos/tempo/src/tempo.gleam", 829). -spec instant_to_local_string(instant()) -> binary(). instant_to_local_string(Instant) -> _pipe = Instant, _pipe@1 = instant_as_local_datetime(_pipe), datetime_to_string(_pipe@1). -file("/home/john/Repos/tempo/src/tempo.gleam", 2476). -spec time_to_duration(time()) -> duration(). time_to_duration(Time) -> _pipe = time_to_microseconds(Time), {duration, _pipe}. -file("/home/john/Repos/tempo/src/tempo.gleam", 2481). -spec time_compare(time(), time()) -> gleam@order:order(). time_compare(A, B) -> case erlang:element(2, A) =:= erlang:element(2, B) of true -> case erlang:element(3, A) =:= erlang:element(3, B) of true -> case erlang:element(4, A) =:= erlang:element(4, B) of true -> case erlang:element(5, A) =:= erlang:element(5, B) of true -> eq; false -> case erlang:element(5, A) < erlang:element( 5, B ) of true -> lt; false -> gt end end; false -> case erlang:element(4, A) < erlang:element(4, B) of true -> lt; false -> gt end end; false -> case erlang:element(3, A) < erlang:element(3, B) of true -> lt; false -> gt end end; false -> case erlang:element(2, A) < erlang:element(2, B) of true -> lt; false -> gt end end. -file("/home/john/Repos/tempo/src/tempo.gleam", 1202). -spec naive_datetime_compare(naive_date_time(), naive_date_time()) -> gleam@order:order(). naive_datetime_compare(A, B) -> case date_compare(erlang:element(2, A), erlang:element(2, B)) of eq -> time_compare(erlang:element(3, A), erlang:element(3, B)); Od -> Od end. -file("/home/john/Repos/tempo/src/tempo.gleam", 1210). -spec naive_datetime_is_earlier(naive_date_time(), naive_date_time()) -> boolean(). naive_datetime_is_earlier(A, B) -> naive_datetime_compare(A, B) =:= lt. -file("/home/john/Repos/tempo/src/tempo.gleam", 1218). -spec naive_datetime_is_earlier_or_equal(naive_date_time(), naive_date_time()) -> boolean(). naive_datetime_is_earlier_or_equal(A, B) -> (naive_datetime_compare(A, B) =:= lt) orelse (naive_datetime_compare(A, B) =:= eq). -file("/home/john/Repos/tempo/src/tempo.gleam", 1227). -spec naive_datetime_is_later_or_equal(naive_date_time(), naive_date_time()) -> boolean(). naive_datetime_is_later_or_equal(A, B) -> (naive_datetime_compare(A, B) =:= gt) orelse (naive_datetime_compare(A, B) =:= eq). -file("/home/john/Repos/tempo/src/tempo.gleam", 2517). -spec time_is_earlier(time(), time()) -> boolean(). time_is_earlier(A, B) -> time_compare(A, B) =:= lt. -file("/home/john/Repos/tempo/src/tempo.gleam", 2522). -spec time_is_earlier_or_equal(time(), time()) -> boolean(). time_is_earlier_or_equal(A, B) -> (time_compare(A, B) =:= lt) orelse (time_compare(A, B) =:= eq). -file("/home/john/Repos/tempo/src/tempo.gleam", 2527). -spec time_is_equal(time(), time()) -> boolean(). time_is_equal(A, B) -> time_compare(A, B) =:= eq. -file("/home/john/Repos/tempo/src/tempo.gleam", 2532). -spec time_is_later(time(), time()) -> boolean(). time_is_later(A, B) -> time_compare(A, B) =:= gt. -file("/home/john/Repos/tempo/src/tempo.gleam", 2537). -spec time_is_later_or_equal(time(), time()) -> boolean(). time_is_later_or_equal(A, B) -> (time_compare(A, B) =:= gt) orelse (time_compare(A, B) =:= eq). -file("/home/john/Repos/tempo/src/tempo.gleam", 2542). -spec time_add(time(), duration()) -> time(). time_add(A, B) -> _pipe = time_to_microseconds(A) + erlang:element(2, B), time_from_microseconds(_pipe). -file("/home/john/Repos/tempo/src/tempo.gleam", 2547). -spec time_subtract(time(), duration()) -> time(). time_subtract(A, B) -> _pipe = time_to_microseconds(A) - erlang:element(2, B), time_from_microseconds(_pipe). -file("/home/john/Repos/tempo/src/tempo.gleam", 2567). -spec duration(integer()) -> duration(). duration(Microseconds) -> {duration, Microseconds}. -file("/home/john/Repos/tempo/src/tempo.gleam", 2572). -spec duration_get_microseconds(duration()) -> integer(). duration_get_microseconds(Duration) -> erlang:element(2, Duration). -file("/home/john/Repos/tempo/src/tempo.gleam", 2577). -spec duration_days(integer()) -> duration(). duration_days(Days) -> _pipe = Days, _pipe@1 = gtempo@internal:imprecise_days(_pipe), duration(_pipe@1). -file("/home/john/Repos/tempo/src/tempo.gleam", 2582). -spec duration_increase(duration(), duration()) -> duration(). duration_increase(A, B) -> {duration, erlang:element(2, A) + erlang:element(2, B)}. -file("/home/john/Repos/tempo/src/tempo.gleam", 1236). -spec naive_datetime_difference(naive_date_time(), naive_date_time()) -> duration(). naive_datetime_difference(A, B) -> _pipe = date_days_apart(erlang:element(2, A), erlang:element(2, B)), _pipe@1 = duration_days(_pipe), duration_increase( _pipe@1, time_difference(erlang:element(3, A), erlang:element(3, B)) ). -file("/home/john/Repos/tempo/src/tempo.gleam", 2587). -spec duration_decrease(duration(), duration()) -> duration(). duration_decrease(A, B) -> {duration, erlang:element(2, A) - erlang:element(2, B)}. -file("/home/john/Repos/tempo/src/tempo.gleam", 2592). -spec duration_absolute(duration()) -> duration(). duration_absolute(Duration) -> case erlang:element(2, Duration) < 0 of true -> _pipe = - (erlang:element(2, Duration)), {duration, _pipe}; false -> Duration end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2600). -spec duration_as_days(duration()) -> integer(). duration_as_days(Duration) -> _pipe = erlang:element(2, Duration), gtempo@internal:as_days_imprecise(_pipe). -file("/home/john/Repos/tempo/src/tempo.gleam", 2605). -spec duration_as_microseconds(duration()) -> integer(). duration_as_microseconds(Duration) -> erlang:element(2, Duration). -file("/home/john/Repos/tempo/src/tempo.gleam", 2634). -spec period_new_naive(naive_date_time(), naive_date_time()) -> period(). period_new_naive(Start, End) -> {Start@1, End@1} = case begin _pipe = Start, naive_datetime_is_earlier_or_equal(_pipe, End) end of true -> {Start, End}; false -> {End, Start} end, {naive_date_time_period, Start@1, End@1}. -file("/home/john/Repos/tempo/src/tempo.gleam", 2646). -spec period_new_date(date(), date()) -> period(). period_new_date(Start, End) -> {Start@1, End@1} = case begin _pipe = Start, date_is_earlier_or_equal(_pipe, End) end of true -> {Start, End}; false -> {End, Start} end, {date_period, Start@1, End@1}. -file("/home/john/Repos/tempo/src/tempo.gleam", 2666). -spec period_get_start_and_end_date_and_time(period()) -> {date(), date(), time(), time()}. period_get_start_and_end_date_and_time(Period) -> case Period of {date_period, Start, End} -> {Start, End, {time, 0, 0, 0, 0}, {time, 24, 0, 0, 0}}; {naive_date_time_period, Start@1, End@1} -> {erlang:element(2, Start@1), erlang:element(2, End@1), erlang:element(3, Start@1), erlang:element(3, End@1)}; {date_time_period, Start@2, End@2} -> {erlang:element(2, Start@2), erlang:element(2, End@2), erlang:element(3, Start@2), erlang:element(3, End@2)} end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2656). -spec period_as_duration(period()) -> duration(). period_as_duration(Period) -> {Start_date, End_date, Start_time, End_time} = period_get_start_and_end_date_and_time( Period ), _pipe = date_days_apart(Start_date, End_date), _pipe@1 = duration_days(_pipe), duration_increase(_pipe@1, time_difference(Start_time, End_time)). -file("/home/john/Repos/tempo/src/tempo.gleam", 2699). -spec period_contains_naive_datetime(period(), naive_date_time()) -> boolean(). period_contains_naive_datetime(Period, Naive_datetime) -> {Start_date, End_date, Start_time, End_time} = period_get_start_and_end_date_and_time( Period ), begin _pipe = Naive_datetime, naive_datetime_is_later_or_equal( _pipe, {naive_date_time, Start_date, Start_time} ) end andalso begin _pipe@1 = Naive_datetime, naive_datetime_is_earlier_or_equal( _pipe@1, {naive_date_time, End_date, End_time} ) end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2723). -spec do_period_comprising_dates(list(date()), date(), date()) -> list(date()). do_period_comprising_dates(Dates, Date, Start_date) -> case begin _pipe = Date, date_is_later_or_equal(_pipe, Start_date) end of true -> do_period_comprising_dates( [Date | Dates], begin _pipe@1 = Date, date_subtract(_pipe@1, 1) end, Start_date ); false -> Dates end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2713). -spec period_comprising_dates(period()) -> list(date()). period_comprising_dates(Period) -> {Start_date, End_date} = case Period of {date_period, Start, End} -> {Start, End}; {naive_date_time_period, Start@1, End@1} -> {erlang:element(2, Start@1), erlang:element(2, End@1)}; {date_time_period, Start@2, End@2} -> {erlang:element(2, Start@2), erlang:element(2, End@2)} end, do_period_comprising_dates([], End_date, Start_date). -file("/home/john/Repos/tempo/src/tempo.gleam", 2757). -spec do_period_comprising_months(list(month_year()), month_year(), date()) -> list(month_year()). do_period_comprising_months(Mys, My, End_date) -> case begin _pipe = date(erlang:element(3, My), erlang:element(2, My), 1), date_is_earlier_or_equal(_pipe, End_date) end of true -> do_period_comprising_months( [My | Mys], month_year_next(My), End_date ); false -> Mys end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2736). -spec period_comprising_months(period()) -> list(month_year()). period_comprising_months(Period) -> {Start_date, End_date} = case Period of {date_period, Start, End} -> {Start, End}; {naive_date_time_period, Start@1, End@1} -> {begin _pipe = Start@1, naive_datetime_get_date(_pipe) end, begin _pipe@1 = End@1, naive_datetime_get_date(_pipe@1) end}; {date_time_period, Start@2, End@2} -> {begin _pipe@2 = Start@2, _pipe@3 = datetime_get_naive(_pipe@2), naive_datetime_get_date(_pipe@3) end, begin _pipe@4 = End@2, _pipe@5 = datetime_get_naive(_pipe@4), naive_datetime_get_date(_pipe@5) end} end, _pipe@6 = do_period_comprising_months( [], {month_year, erlang:element(3, Start_date), erlang:element(2, Start_date)}, End_date ), lists:reverse(_pipe@6). -file("/home/john/Repos/tempo/src/tempo.gleam", 2891). -spec get_datetime_format_str(date_time_format()) -> binary(). get_datetime_format_str(Format) -> case Format of iso8601_seconds -> <<"YYYY-MM-DDTHH:mm:sszz"/utf8>>; iso8601_milli -> <<"YYYY-MM-DDTHH:mm:ss.SSSzz"/utf8>>; iso8601_micro -> <<"YYYY-MM-DDTHH:mm:ss.SSSSzz"/utf8>>; http -> <<"ddd, DD MMM YYYY HH:mm:ss [GMT]"/utf8>>; {date_format, iso8601_date} -> <<"YYYY-MM-DD"/utf8>>; {time_format, iso8601_time} -> <<"HH:mm:sszz"/utf8>>; {time_format, iso8601_time_milli} -> <<"HH:mm:ss.SSSzz"/utf8>>; {time_format, iso8601_time_micro} -> <<"HH:mm:ss.SSSSzz"/utf8>>; {time_format, {custom_time, Format@1}} -> Format@1; {time_format, {custom_time_localised, Format@2, _}} -> Format@2; {date_format, {custom_date, Format@3}} -> Format@3; {date_format, {custom_date_localised, Format@4, _}} -> Format@4; {custom, Format@5} -> Format@5; {custom_localised, Format@6, _} -> Format@6 end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2911). -spec get_naive_datetime_format_str(naive_date_time_format()) -> binary(). get_naive_datetime_format_str(Format) -> case Format of naive_iso8601_seconds -> <<"YYYY-MM-DDTHH:mm:ss"/utf8>>; naive_iso8601_milli -> <<"YYYY-MM-DDTHH:mm:ss.SSS"/utf8>>; naive_iso8601_micro -> <<"YYYY-MM-DDTHH:mm:ss.SSSS"/utf8>>; {custom_naive, Format@1} -> Format@1; {custom_naive_localised, Format@2, _} -> Format@2; {naive_date_format, iso8601_date} -> <<"YYYY-MM-DD"/utf8>>; {naive_time_format, iso8601_time} -> <<"HH:mm:ss"/utf8>>; {naive_time_format, iso8601_time_milli} -> <<"HH:mm:ss.SSS"/utf8>>; {naive_time_format, iso8601_time_micro} -> <<"HH:mm:ss.SSSS"/utf8>>; {naive_time_format, {custom_time, Format@3}} -> Format@3; {naive_time_format, {custom_time_localised, Format@4, _}} -> Format@4; {naive_date_format, {custom_date, Format@5}} -> Format@5; {naive_date_format, {custom_date_localised, Format@6, _}} -> Format@6 end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2930). -spec get_time_format_str(time_format()) -> binary(). get_time_format_str(Format) -> case Format of iso8601_time -> <<"HH:mm:sszz"/utf8>>; iso8601_time_milli -> <<"HH:mm:ss.SSSzz"/utf8>>; iso8601_time_micro -> <<"HH:mm:ss.SSSSzz"/utf8>>; {custom_time, Format@1} -> Format@1; {custom_time_localised, Format@2, _} -> Format@2 end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2941). -spec get_date_format_str(date_format()) -> binary(). get_date_format_str(Format) -> case Format of iso8601_date -> <<"YYYY-MM-DD"/utf8>>; {custom_date, Format@1} -> Format@1; {custom_date_localised, Format@2, _} -> Format@2 end. -file("/home/john/Repos/tempo/src/tempo.gleam", 3463). -spec consume_one_or_two_digits(binary(), fun((integer()) -> GPL)) -> {ok, {GPL, binary()}} | {error, nil}. consume_one_or_two_digits(Str, Constructor) -> case begin _pipe = gleam@string:slice(Str, 0, 2), gleam_stdlib:parse_int(_pipe) end of {ok, Val} -> {ok, {Constructor(Val), gleam@string:drop_start(Str, 2)}}; {error, _} -> case begin _pipe@1 = gleam@string:slice(Str, 0, 1), gleam_stdlib:parse_int(_pipe@1) end of {ok, Val@1} -> {ok, {Constructor(Val@1), gleam@string:drop_start(Str, 1)}}; {error, _} -> {error, nil} end end. -file("/home/john/Repos/tempo/src/tempo.gleam", 3474). -spec consume_two_digits(binary(), fun((integer()) -> GQE)) -> {ok, {GQE, binary()}} | {error, nil}. consume_two_digits(Str, Constructor) -> gleam@result:map( begin _pipe = gleam@string:slice(Str, 0, 2), gleam_stdlib:parse_int(_pipe) end, fun(Val) -> {Constructor(Val), gleam@string:drop_start(Str, 2)} end ). -file("/home/john/Repos/tempo/src/tempo.gleam", 3481). -spec find_date(list(datetime_part())) -> {ok, date()} | {error, tempo@error:date_parse_error()}. find_date(Parts) -> gleam@result:'try'( begin _pipe = gleam@list:find_map(Parts, fun(P) -> case P of {year, Y} -> {ok, Y}; _ -> {error, nil} end end), gleam@result:replace_error( _pipe, {date_invalid_format, <<"Missing year"/utf8>>} ) end, fun(Year) -> gleam@result:'try'( begin _pipe@1 = gleam@list:find_map(Parts, fun(P@1) -> case P@1 of {month, M} -> {ok, M}; _ -> {error, nil} end end), gleam@result:replace_error( _pipe@1, {date_invalid_format, <<"Missing month"/utf8>>} ) end, fun(Month) -> gleam@result:'try'( begin _pipe@2 = gleam@list:find_map( Parts, fun(P@2) -> case P@2 of {day, D} -> {ok, D}; _ -> {error, nil} end end ), gleam@result:replace_error( _pipe@2, {date_invalid_format, <<"Missing day"/utf8>>} ) end, fun(Day) -> _pipe@3 = new_date(Year, Month, Day), gleam@result:map_error( _pipe@3, fun(_capture) -> {date_out_of_bounds, <<"Out of bounds"/utf8>>, _capture} end ) end ) end ) end ). -file("/home/john/Repos/tempo/src/tempo.gleam", 3517). -spec find_time(list(datetime_part())) -> {ok, time()} | {error, tempo@error:time_parse_error()}. find_time(Parts) -> gleam@result:'try'( begin gleam@result:try_recover( gleam@list:find_map(Parts, fun(P) -> case P of {hour, H} -> {ok, H}; _ -> {error, nil} end end), fun(_) -> gleam@result:'try'( begin _pipe = gleam@list:find_map( Parts, fun(P@1) -> case P@1 of {twelve_hour, O} -> {ok, O}; _ -> {error, nil} end end ), gleam@result:replace_error( _pipe, {time_invalid_format, <<"Missing hour"/utf8>>} ) end, fun(Twelve_hour) -> Am_period = gleam@list:find_map( Parts, fun(P@2) -> case P@2 of am_period -> {ok, nil}; _ -> {error, nil} end end ), Pm_period = gleam@list:find_map( Parts, fun(P@3) -> case P@3 of pm_period -> {ok, nil}; _ -> {error, nil} end end ), case {Am_period, Pm_period} of {{ok, nil}, {error, nil}} -> _pipe@1 = adjust_12_hour_to_24_hour( Twelve_hour, true ), {ok, _pipe@1}; {{error, nil}, {ok, nil}} -> _pipe@2 = adjust_12_hour_to_24_hour( Twelve_hour, false ), {ok, _pipe@2}; {_, _} -> {error, {time_invalid_format, <<"Missing period in 12 hour time"/utf8>>}} end end ) end ) end, fun(Hour) -> gleam@result:'try'( begin _pipe@3 = gleam@list:find_map(Parts, fun(P@4) -> case P@4 of {minute, M} -> {ok, M}; _ -> {error, nil} end end), gleam@result:replace_error( _pipe@3, {time_invalid_format, <<"Missing minute"/utf8>>} ) end, fun(Minute) -> Second = begin _pipe@4 = gleam@list:find_map( Parts, fun(P@5) -> case P@5 of {second, S} -> {ok, S}; _ -> {error, nil} end end ), gleam@result:unwrap(_pipe@4, 0) end, Millisecond = gleam@list:find_map( Parts, fun(P@6) -> case P@6 of {millisecond, N} -> {ok, N}; _ -> {error, nil} end end ), Microsecond = gleam@list:find_map( Parts, fun(P@7) -> case P@7 of {microsecond, N@1} -> {ok, N@1}; _ -> {error, nil} end end ), _pipe@5 = case {Microsecond, Millisecond} of {{ok, Micro}, _} -> new_time_micro(Hour, Minute, Second, Micro); {_, {ok, Milli}} -> new_time_milli(Hour, Minute, Second, Milli); {_, _} -> new_time(Hour, Minute, Second) end, gleam@result:map_error( _pipe@5, fun(_capture) -> {time_out_of_bounds, <<"Out of bounds"/utf8>>, _capture} end ) end ) end ). -file("/home/john/Repos/tempo/src/tempo.gleam", 3623). -spec result_guard({ok, GXA} | {error, any()}, GXD, fun((GXA) -> GXD)) -> GXD. result_guard(E, V, Run) -> case E of {error, _} -> V; {ok, Ok} -> Run(Ok) end. -file("/home/john/Repos/tempo/src/tempo.gleam", 3637). -spec now_utc_ffi() -> integer(). now_utc_ffi() -> tempo_ffi:now(). -file("/home/john/Repos/tempo/src/tempo.gleam", 3642). -spec now_monotonic_ffi() -> integer(). now_monotonic_ffi() -> tempo_ffi:now_monotonic(). -file("/home/john/Repos/tempo/src/tempo.gleam", 3647). -spec now_unique_ffi() -> integer(). now_unique_ffi() -> tempo_ffi:now_unique(). -file("/home/john/Repos/tempo/src/tempo.gleam", 3657). -spec offset_local_minutes() -> integer(). offset_local_minutes() -> tempo_ffi:local_offset(). -file("/home/john/Repos/tempo/src/tempo.gleam", 3650). -spec offset_local_micro() -> integer(). offset_local_micro() -> tempo_ffi:local_offset() * 60000000. -file("/home/john/Repos/tempo/src/tempo.gleam", 42). -spec now() -> instant(). now() -> {instant, tempo_ffi:now(), offset_local_micro(), tempo_ffi:now_monotonic(), tempo_ffi:now_unique()}. -file("/home/john/Repos/tempo/src/tempo.gleam", 113). -spec instant_since(instant()) -> duration(). instant_since(Start) -> _pipe = now(), _pipe@1 = instant_difference(Start, _pipe), duration_absolute(_pipe@1). -file("/home/john/Repos/tempo/src/tempo.gleam", 128). -spec instant_since_formatted(instant()) -> binary(). instant_since_formatted(Start) -> Dur = instant_since(Start), gtempo@internal:format(erlang:element(2, Dur)). -file("/home/john/Repos/tempo/src/tempo.gleam", 217). -spec compare_utc_date(date()) -> gleam@order:order(). compare_utc_date(Date) -> _pipe = now(), _pipe@1 = instant_as_utc_date(_pipe), date_compare(_pipe@1, Date). -file("/home/john/Repos/tempo/src/tempo.gleam", 233). -spec compare_local_date(date()) -> gleam@order:order(). compare_local_date(Date) -> _pipe = now(), _pipe@1 = instant_as_local_date(_pipe), date_compare(_pipe@1, Date). -file("/home/john/Repos/tempo/src/tempo.gleam", 246). -spec is_utc_date_earlier(date()) -> boolean(). is_utc_date_earlier(Date) -> date_is_earlier( begin _pipe = now(), instant_as_utc_date(_pipe) end, Date ). -file("/home/john/Repos/tempo/src/tempo.gleam", 259). -spec is_local_date_earlier(date()) -> boolean(). is_local_date_earlier(Date) -> date_is_earlier( begin _pipe = now(), instant_as_local_date(_pipe) end, Date ). -file("/home/john/Repos/tempo/src/tempo.gleam", 272). -spec is_utc_date_earlier_or_equal(date()) -> boolean(). is_utc_date_earlier_or_equal(Date) -> date_is_earlier_or_equal( begin _pipe = now(), instant_as_utc_date(_pipe) end, Date ). -file("/home/john/Repos/tempo/src/tempo.gleam", 285). -spec is_local_date_earlier_or_equal(date()) -> boolean(). is_local_date_earlier_or_equal(Date) -> date_is_earlier_or_equal( begin _pipe = now(), instant_as_local_date(_pipe) end, Date ). -file("/home/john/Repos/tempo/src/tempo.gleam", 298). -spec is_utc_date_equal(date()) -> boolean(). is_utc_date_equal(Date) -> date_is_equal( begin _pipe = now(), instant_as_utc_date(_pipe) end, Date ). -file("/home/john/Repos/tempo/src/tempo.gleam", 311). -spec is_local_date_equal(date()) -> boolean(). is_local_date_equal(Date) -> date_is_equal( begin _pipe = now(), instant_as_local_date(_pipe) end, Date ). -file("/home/john/Repos/tempo/src/tempo.gleam", 324). -spec is_utc_date_later(date()) -> boolean(). is_utc_date_later(Date) -> date_is_later( begin _pipe = now(), instant_as_utc_date(_pipe) end, Date ). -file("/home/john/Repos/tempo/src/tempo.gleam", 337). -spec is_local_date_later(date()) -> boolean(). is_local_date_later(Date) -> date_is_later( begin _pipe = now(), instant_as_local_date(_pipe) end, Date ). -file("/home/john/Repos/tempo/src/tempo.gleam", 350). -spec is_utc_date_later_or_equal(date()) -> boolean(). is_utc_date_later_or_equal(Date) -> date_is_later_or_equal( begin _pipe = now(), instant_as_utc_date(_pipe) end, Date ). -file("/home/john/Repos/tempo/src/tempo.gleam", 363). -spec is_local_date_later_or_equal(date()) -> boolean(). is_local_date_later_or_equal(Date) -> date_is_later_or_equal( begin _pipe = now(), instant_as_local_date(_pipe) end, Date ). -file("/home/john/Repos/tempo/src/tempo.gleam", 376). -spec compare_utc_time(time()) -> gleam@order:order(). compare_utc_time(Time) -> time_compare( begin _pipe = now(), instant_as_utc_time(_pipe) end, Time ). -file("/home/john/Repos/tempo/src/tempo.gleam", 389). -spec compare_local_time(time()) -> gleam@order:order(). compare_local_time(Time) -> time_compare( begin _pipe = now(), instant_as_local_time(_pipe) end, Time ). -file("/home/john/Repos/tempo/src/tempo.gleam", 402). -spec is_utc_time_earlier(time()) -> boolean(). is_utc_time_earlier(Time) -> time_is_earlier( begin _pipe = now(), instant_as_utc_time(_pipe) end, Time ). -file("/home/john/Repos/tempo/src/tempo.gleam", 415). -spec is_local_time_earlier(time()) -> boolean(). is_local_time_earlier(Time) -> time_is_earlier( begin _pipe = now(), instant_as_local_time(_pipe) end, Time ). -file("/home/john/Repos/tempo/src/tempo.gleam", 428). -spec is_utc_time_earlier_or_equal(time()) -> boolean(). is_utc_time_earlier_or_equal(Time) -> time_is_earlier_or_equal( begin _pipe = now(), instant_as_utc_time(_pipe) end, Time ). -file("/home/john/Repos/tempo/src/tempo.gleam", 441). -spec is_local_time_earlier_or_equal(time()) -> boolean(). is_local_time_earlier_or_equal(Time) -> time_is_earlier_or_equal( begin _pipe = now(), instant_as_local_time(_pipe) end, Time ). -file("/home/john/Repos/tempo/src/tempo.gleam", 454). -spec is_utc_time_equal(time()) -> boolean(). is_utc_time_equal(Time) -> time_is_equal( begin _pipe = now(), instant_as_utc_time(_pipe) end, Time ). -file("/home/john/Repos/tempo/src/tempo.gleam", 467). -spec is_local_time_equal(time()) -> boolean(). is_local_time_equal(Time) -> time_is_equal( begin _pipe = now(), instant_as_local_time(_pipe) end, Time ). -file("/home/john/Repos/tempo/src/tempo.gleam", 480). -spec is_utc_time_later(time()) -> boolean(). is_utc_time_later(Time) -> time_is_later( begin _pipe = now(), instant_as_utc_time(_pipe) end, Time ). -file("/home/john/Repos/tempo/src/tempo.gleam", 493). -spec is_local_time_later(time()) -> boolean(). is_local_time_later(Time) -> time_is_later( begin _pipe = now(), instant_as_local_time(_pipe) end, Time ). -file("/home/john/Repos/tempo/src/tempo.gleam", 506). -spec is_utc_time_later_or_equal(time()) -> boolean(). is_utc_time_later_or_equal(Time) -> time_is_later_or_equal( begin _pipe = now(), instant_as_utc_time(_pipe) end, Time ). -file("/home/john/Repos/tempo/src/tempo.gleam", 519). -spec is_local_time_later_or_equal(time()) -> boolean(). is_local_time_later_or_equal(Time) -> time_is_later_or_equal( begin _pipe = now(), instant_as_local_time(_pipe) end, Time ). -file("/home/john/Repos/tempo/src/tempo.gleam", 593). -spec utc_time_difference_from(time()) -> duration(). utc_time_difference_from(Start) -> _pipe = now(), _pipe@1 = instant_as_utc_time(_pipe), time_difference(Start, _pipe@1). -file("/home/john/Repos/tempo/src/tempo.gleam", 608). -spec local_time_difference_from(time()) -> duration(). local_time_difference_from(Start) -> _pipe = now(), _pipe@1 = instant_as_utc_time(_pipe), time_difference(Start, _pipe@1). -file("/home/john/Repos/tempo/src/tempo.gleam", 623). -spec utc_time_since(time()) -> duration(). utc_time_since(Start) -> case utc_time_difference_from(Start) of {duration, Diff} when Diff > 0 -> {duration, Diff}; _ -> {duration, 0} end. -file("/home/john/Repos/tempo/src/tempo.gleam", 641). -spec local_time_since(time()) -> duration(). local_time_since(Start) -> case local_time_difference_from(Start) of {duration, Diff} when Diff > 0 -> {duration, Diff}; _ -> {duration, 0} end. -file("/home/john/Repos/tempo/src/tempo.gleam", 659). -spec utc_time_until(time()) -> duration(). utc_time_until(End) -> case begin _pipe = now(), _pipe@1 = instant_as_utc_time(_pipe), time_difference(_pipe@1, End) end of {duration, Diff} when Diff > 0 -> {duration, Diff}; _ -> {duration, 0} end. -file("/home/john/Repos/tempo/src/tempo.gleam", 677). -spec local_time_until(time()) -> duration(). local_time_until(End) -> case begin _pipe = now(), _pipe@1 = instant_as_local_time(_pipe), time_difference(_pipe@1, End) end of {duration, Diff} when Diff > 0 -> {duration, Diff}; _ -> {duration, 0} end. -file("/home/john/Repos/tempo/src/tempo.gleam", 693). -spec utc_date_difference_from(date()) -> integer(). utc_date_difference_from(Start) -> _pipe = now(), _pipe@1 = instant_as_utc_date(_pipe), date_days_apart(Start, _pipe@1). -file("/home/john/Repos/tempo/src/tempo.gleam", 706). -spec local_date_difference_from(date()) -> integer(). local_date_difference_from(Start) -> _pipe = now(), _pipe@1 = instant_as_local_date(_pipe), date_days_apart(Start, _pipe@1). -file("/home/john/Repos/tempo/src/tempo.gleam", 720). -spec utc_days_since(date()) -> integer(). utc_days_since(Start) -> case utc_date_difference_from(Start) of Diff when Diff > 0 -> Diff; _ -> 0 end. -file("/home/john/Repos/tempo/src/tempo.gleam", 737). -spec local_days_since(date()) -> integer(). local_days_since(Start) -> case local_date_difference_from(Start) of Diff when Diff > 0 -> Diff; _ -> 0 end. -file("/home/john/Repos/tempo/src/tempo.gleam", 754). -spec utc_days_until(date()) -> integer(). utc_days_until(End) -> case begin _pipe = now(), _pipe@1 = instant_as_utc_date(_pipe), date_days_apart(_pipe@1, End) end of Diff when Diff > 0 -> Diff; _ -> 0 end. -file("/home/john/Repos/tempo/src/tempo.gleam", 771). -spec local_days_until(date()) -> integer(). local_days_until(End) -> case begin _pipe = now(), _pipe@1 = instant_as_local_date(_pipe), date_days_apart(_pipe@1, End) end of Diff when Diff > 0 -> Diff; _ -> 0 end. -file("/home/john/Repos/tempo/src/tempo.gleam", 3267). -spec consume_part(binary(), binary()) -> {ok, {datetime_part(), binary()}} | {error, binary()}. consume_part(Fmt, Str) -> _pipe@15 = case Fmt of <<"YY"/utf8>> -> gleam@result:map( begin _pipe = gleam@string:slice(Str, 0, 2), gleam_stdlib:parse_int(_pipe) end, fun(Val) -> Current_year = tempo_ffi:current_year(), Current_century = (Current_year div 100) * 100, Current_two_year_date = Current_year rem 100, case Val > Current_two_year_date of true -> {{year, (Current_century - 100) + Val}, gleam@string:drop_start(Str, 2)}; false -> {{year, Current_century + Val}, gleam@string:drop_start(Str, 2)} end end ); <<"YYYY"/utf8>> -> gleam@result:map( begin _pipe@1 = gleam@string:slice(Str, 0, 4), gleam_stdlib:parse_int(_pipe@1) end, fun(Year) -> {{year, Year}, gleam@string:drop_start(Str, 4)} end ); <<"M"/utf8>> -> consume_one_or_two_digits(Str, fun(Field@0) -> {month, Field@0} end); <<"MM"/utf8>> -> consume_two_digits(Str, fun(Field@0) -> {month, Field@0} end); <<"MMM"/utf8>> -> case Str of <<"Jan"/utf8, Rest/binary>> -> {ok, {{month, 1}, Rest}}; <<"Feb"/utf8, Rest@1/binary>> -> {ok, {{month, 2}, Rest@1}}; <<"Mar"/utf8, Rest@2/binary>> -> {ok, {{month, 3}, Rest@2}}; <<"Apr"/utf8, Rest@3/binary>> -> {ok, {{month, 4}, Rest@3}}; <<"May"/utf8, Rest@4/binary>> -> {ok, {{month, 5}, Rest@4}}; <<"Jun"/utf8, Rest@5/binary>> -> {ok, {{month, 6}, Rest@5}}; <<"Jul"/utf8, Rest@6/binary>> -> {ok, {{month, 7}, Rest@6}}; <<"Aug"/utf8, Rest@7/binary>> -> {ok, {{month, 8}, Rest@7}}; <<"Sep"/utf8, Rest@8/binary>> -> {ok, {{month, 9}, Rest@8}}; <<"Oct"/utf8, Rest@9/binary>> -> {ok, {{month, 10}, Rest@9}}; <<"Nov"/utf8, Rest@10/binary>> -> {ok, {{month, 11}, Rest@10}}; <<"Dec"/utf8, Rest@11/binary>> -> {ok, {{month, 12}, Rest@11}}; _ -> {error, nil} end; <<"MMMM"/utf8>> -> case Str of <<"January"/utf8, Rest@12/binary>> -> {ok, {{month, 1}, Rest@12}}; <<"February"/utf8, Rest@13/binary>> -> {ok, {{month, 2}, Rest@13}}; <<"March"/utf8, Rest@14/binary>> -> {ok, {{month, 3}, Rest@14}}; <<"April"/utf8, Rest@15/binary>> -> {ok, {{month, 4}, Rest@15}}; <<"May"/utf8, Rest@16/binary>> -> {ok, {{month, 5}, Rest@16}}; <<"June"/utf8, Rest@17/binary>> -> {ok, {{month, 6}, Rest@17}}; <<"July"/utf8, Rest@18/binary>> -> {ok, {{month, 7}, Rest@18}}; <<"August"/utf8, Rest@19/binary>> -> {ok, {{month, 8}, Rest@19}}; <<"September"/utf8, Rest@20/binary>> -> {ok, {{month, 9}, Rest@20}}; <<"October"/utf8, Rest@21/binary>> -> {ok, {{month, 10}, Rest@21}}; <<"November"/utf8, Rest@22/binary>> -> {ok, {{month, 11}, Rest@22}}; <<"December"/utf8, Rest@23/binary>> -> {ok, {{month, 12}, Rest@23}}; _ -> {error, nil} end; <<"D"/utf8>> -> consume_one_or_two_digits(Str, fun(Field@0) -> {day, Field@0} end); <<"DD"/utf8>> -> consume_two_digits(Str, fun(Field@0) -> {day, Field@0} end); <<"H"/utf8>> -> consume_one_or_two_digits(Str, fun(Field@0) -> {hour, Field@0} end); <<"HH"/utf8>> -> consume_two_digits(Str, fun(Field@0) -> {hour, Field@0} end); <<"h"/utf8>> -> consume_one_or_two_digits( Str, fun(Field@0) -> {twelve_hour, Field@0} end ); <<"hh"/utf8>> -> consume_two_digits(Str, fun(Field@0) -> {twelve_hour, Field@0} end); <<"a"/utf8>> -> case Str of <<"am"/utf8, Rest@24/binary>> -> {ok, {am_period, Rest@24}}; <<"pm"/utf8, Rest@25/binary>> -> {ok, {pm_period, Rest@25}}; _ -> {error, nil} end; <<"A"/utf8>> -> case Str of <<"AM"/utf8, Rest@26/binary>> -> {ok, {am_period, Rest@26}}; <<"PM"/utf8, Rest@27/binary>> -> {ok, {pm_period, Rest@27}}; _ -> {error, nil} end; <<"m"/utf8>> -> consume_one_or_two_digits( Str, fun(Field@0) -> {minute, Field@0} end ); <<"mm"/utf8>> -> consume_two_digits(Str, fun(Field@0) -> {minute, Field@0} end); <<"s"/utf8>> -> consume_one_or_two_digits( Str, fun(Field@0) -> {second, Field@0} end ); <<"ss"/utf8>> -> consume_two_digits(Str, fun(Field@0) -> {second, Field@0} end); <<"SSS"/utf8>> -> gleam@result:map( begin _pipe@2 = gleam@string:slice(Str, 0, 3), gleam_stdlib:parse_int(_pipe@2) end, fun(Milli) -> {{millisecond, Milli}, gleam@string:drop_start(Str, 3)} end ); <<"SSSS"/utf8>> -> gleam@result:map( begin _pipe@3 = gleam@string:slice(Str, 0, 6), gleam_stdlib:parse_int(_pipe@3) end, fun(Micro) -> {{microsecond, Micro}, gleam@string:drop_start(Str, 6)} end ); <<"z"/utf8>> -> gleam@result:try_recover( begin _pipe@4 = gleam@string:slice(Str, 0, 6), _pipe@6 = (fun(Offset) -> gleam@result:'try'( begin _pipe@5 = gleam@regexp:from_string( <<"[-+]\\d\\d:\\d\\d"/utf8>> ), gleam@result:replace_error(_pipe@5, nil) end, fun(Re) -> case gleam@regexp:check(Re, Offset) of true -> {ok, Offset}; false -> {error, nil} end end ) end)(_pipe@4), gleam@result:map( _pipe@6, fun(Offset@1) -> {{offset_str, Offset@1}, gleam@string:drop_start(Str, 6)} end ) end, fun(_) -> gleam@result:try_recover( begin _pipe@7 = gleam@string:slice(Str, 0, 5), _pipe@9 = (fun(Offset@2) -> gleam@result:'try'( begin _pipe@8 = gleam@regexp:from_string( <<"[-+]\\d\\d\\d\\d"/utf8>> ), gleam@result:replace_error(_pipe@8, nil) end, fun(Re@1) -> case gleam@regexp:check(Re@1, Offset@2) of true -> {ok, Offset@2}; false -> {error, nil} end end ) end)(_pipe@7), gleam@result:map( _pipe@9, fun(Offset@3) -> {{offset_str, Offset@3}, gleam@string:drop_start(Str, 5)} end ) end, fun(_) -> gleam@result:try_recover( begin _pipe@10 = gleam@string:slice(Str, 0, 3), _pipe@12 = (fun(Offset@4) -> gleam@result:'try'( begin _pipe@11 = gleam@regexp:from_string( <<"[-+]\\d\\d"/utf8>> ), gleam@result:replace_error( _pipe@11, nil ) end, fun(Re@2) -> case gleam@regexp:check( Re@2, Offset@4 ) of true -> {ok, Offset@4}; false -> {error, nil} end end ) end)(_pipe@10), gleam@result:map( _pipe@12, fun(Offset@5) -> {{offset_str, Offset@5}, gleam@string:drop_start(Str, 3)} end ) end, fun(_) -> gleam@result:try_recover( begin _pipe@13 = gleam@string:slice( Str, 0, 1 ), _pipe@14 = (fun(Offset@6) -> case (Offset@6 =:= <<"Z"/utf8>>) orelse (Offset@6 =:= <<"z"/utf8>>) of true -> {ok, Offset@6}; false -> {error, nil} end end)(_pipe@13), gleam@result:map( _pipe@14, fun(Offset@7) -> {{offset_str, Offset@7}, gleam@string:drop_start( Str, 1 )} end ) end, fun(_) -> {error, nil} end ) end ) end ) end ); <<"Z"/utf8>> -> {ok, {{offset_str, gleam@string:slice(Str, 0, 6)}, gleam@string:drop_start(Str, 6)}}; <<"ZZ"/utf8>> -> {ok, {{offset_str, gleam@string:slice(Str, 0, 5)}, gleam@string:drop_start(Str, 5)}}; Passthrough -> Fmt_length = string:length(Passthrough), Str_slice = gleam@string:slice(Str, 0, Fmt_length), case Str_slice =:= Passthrough of true -> {ok, {passthrough, gleam@string:drop_start(Str, Fmt_length)}}; false -> {error, nil} end end, gleam@result:map_error( _pipe@15, fun(_) -> <<"Unable to parse directive "/utf8, Fmt/binary>> end ). -file("/home/john/Repos/tempo/src/tempo.gleam", 3231). -spec consume_format(binary(), binary()) -> {ok, {list(datetime_part()), binary()}} | {error, binary()}. consume_format(Str, 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}|SSS{3,5}|."/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"/utf8>>, function => <<"consume_format"/utf8>>, line => 3232}) end, _pipe = gleam@regexp:scan(Re, Fmt), gleam@list:fold(_pipe, {ok, {[], Str}}, fun(Acc, Match) -> case Acc of {ok, Acc@1} -> {Consumed, Input} = Acc@1, Res = case Match of {match, Content, []} -> consume_part(Content, Input); {match, _, [{some, Sub}]} -> {ok, {passthrough, gleam@string:drop_start( Input, string:length(Sub) )}}; {match, Content@1, _} -> {ok, {passthrough, gleam@string:drop_start( Input, string:length(Content@1) )}} end, case Res of {ok, {Part, Not_consumed}} -> {ok, {[Part | Consumed], Not_consumed}}; {error, Err} -> {error, Err} end; {error, Err@1} -> {error, Err@1} end end). -file("/home/john/Repos/tempo/src/tempo.gleam", 66). -spec now_adjusted(duration()) -> date_time(). now_adjusted(Duration) -> New_ts = erlang:element(2, now()) + erlang:element(2, Duration), {date_time, date_from_unix_seconds(New_ts div 1000000), time_from_unix_micro(New_ts), {offset, 0}}. -file("/home/john/Repos/tempo/src/tempo.gleam", 796). -spec instant_as_utc_datetime(instant()) -> date_time(). instant_as_utc_datetime(Instant) -> {date_time, instant_as_utc_date(Instant), instant_as_utc_time(Instant), {offset, 0}}. -file("/home/john/Repos/tempo/src/tempo.gleam", 824). -spec instant_to_utc_string(instant()) -> binary(). instant_to_utc_string(Instant) -> _pipe = Instant, _pipe@1 = instant_as_utc_datetime(_pipe), datetime_to_string(_pipe@1). -file("/home/john/Repos/tempo/src/tempo.gleam", 1368). -spec offset_from_string(binary()) -> {ok, offset()} | {error, tempo@error:offset_parse_error()}. offset_from_string(Offset_str) -> gleam@result:'try'(case Offset_str of <<"Z"/utf8>> -> {ok, {offset, 0}}; <<"z"/utf8>> -> {ok, {offset, 0}}; _ -> gleam@result:'try'( case gleam@string:split(Offset_str, <<":"/utf8>>) of [Hour, Minute] -> case {string:length(Hour), string:length(Minute)} of {3, 2} -> {ok, {gleam@string:slice(Hour, 0, 1), gleam@string:slice(Hour, 1, 2), Minute}}; {_, _} -> {error, {offset_invalid_format, Offset_str}} end; _ -> case string:length(Offset_str) of 5 -> {ok, {gleam@string:slice(Offset_str, 0, 1), gleam@string:slice(Offset_str, 1, 2), gleam@string:slice(Offset_str, 3, 2)}}; 3 -> {ok, {gleam@string:slice(Offset_str, 0, 1), gleam@string:slice(Offset_str, 1, 2), <<"0"/utf8>>}}; 2 -> {ok, {gleam@string:slice(Offset_str, 0, 1), gleam@string:slice(Offset_str, 1, 1), <<"0"/utf8>>}}; _ -> {error, {offset_invalid_format, Offset_str}} end end, fun(_use0) -> {Sign, Hour@1, Minute@1} = _use0, case {Sign, gleam_stdlib:parse_int(Hour@1), gleam_stdlib:parse_int(Minute@1)} of {_, {ok, 0}, {ok, 0}} -> {ok, {offset, 0}}; {<<"-"/utf8>>, {ok, Hour@2}, {ok, Minute@2}} when (Hour@2 =< 24) andalso (Minute@2 =< 60) -> {ok, {offset, - ((Hour@2 * 60) + Minute@2)}}; {<<"+"/utf8>>, {ok, Hour@3}, {ok, Minute@3}} when (Hour@3 =< 24) andalso (Minute@3 =< 60) -> {ok, {offset, (Hour@3 * 60) + Minute@3}}; {_, _, _} -> {error, {offset_invalid_format, Offset_str}} end end ) end, fun(Offset) -> _pipe = validate_offset(Offset), gleam@result:replace_error( _pipe, {offset_out_of_bounds, Offset_str} ) end). -file("/home/john/Repos/tempo/src/tempo.gleam", 2995). -spec parse_any(binary()) -> {gleam@option:option(date()), gleam@option:option(time()), gleam@option:option(offset())}. parse_any(Str) -> Empty_result = {none, none, none}, result_guard( gleam@regexp:from_string(<<"\\d{9,}"/utf8>>), Empty_result, fun(Serial_re) -> gleam@bool:guard( gleam@regexp:check(Serial_re, Str), Empty_result, fun() -> result_guard( gleam@regexp:from_string( <<"(\\d{4})[-_/\\.\\s,]{0,2}(\\d{1,2})[-_/\\.\\s,]{0,2}(\\d{1,2})"/utf8>> ), Empty_result, fun(Date_re) -> result_guard( gleam@regexp:from_string( <<"(\\d{1,2}|January|Jan|january|jan|February|Feb|february|feb|March|Mar|march|mar|April|Apr|april|apr|May|may|June|Jun|june|jun|July|Jul|july|jul|August|Aug|august|aug|September|Sep|september|sep|October|Oct|october|oct|November|Nov|november|nov|December|Dec|december|dec)[-_/\\.\\s,]{0,2}(\\d{1,2})(?:st|nd|rd|th)?[-_/\\.\\s,]{0,2}(\\d{4})"/utf8>> ), Empty_result, fun(Date_human_re) -> result_guard( gleam@regexp:from_string( <<"(\\d{1,2})[:_\\.\\s]{0,1}(\\d{1,2})[:_\\.\\s]{0,1}(\\d{0,2})[\\.]{0,1}(\\d{0,9})\\s*(AM|PM|am|pm)?"/utf8>> ), Empty_result, fun(Time_re) -> result_guard( gleam@regexp:from_string( <<"([-+]\\d{2}):{0,1}(\\d{1,2})?"/utf8>> ), Empty_result, fun(Offset_re) -> result_guard( gleam@regexp:from_string( <<"(?> ), Empty_result, fun(Offset_char_re) -> Unconsumed = Str, {Date@1, Unconsumed@1} = (case gleam@regexp:scan( Date_re, Unconsumed ) of [{match, Content, [{some, Year}, {some, Month}, {some, Day}]} | _] -> case {gleam_stdlib:parse_int( Year ), gleam_stdlib:parse_int( Month ), gleam_stdlib:parse_int( Day )} of {{ok, Year@1}, {ok, Month@1}, {ok, Day@1}} -> case new_date( Year@1, Month@1, Day@1 ) of {ok, Date} -> {{some, Date}, gleam@string:replace( Unconsumed, Content, <<""/utf8>> )}; _ -> {none, Unconsumed} end; {_, _, _} -> {none, Unconsumed} end; _ -> {none, Unconsumed} end), {Date@3, Unconsumed@2} = (case Date@1 of {some, D} -> {{some, D}, Unconsumed@1}; none -> case gleam@regexp:scan( Date_human_re, Unconsumed@1 ) of [{match, Content@1, [{some, Month@2}, {some, Day@2}, {some, Year@2}]} | _] -> case {gleam_stdlib:parse_int( Year@2 ), begin _pipe = gleam_stdlib:parse_int( Month@2 ), _pipe@1 = gleam@result:'try'( _pipe, fun month_from_int/1 ), gleam@result:try_recover( _pipe@1, fun( _ ) -> _pipe@2 = month_from_short_string( Month@2 ), gleam@result:try_recover( _pipe@2, fun( _ ) -> month_from_long_string( Month@2 ) end ) end ) end, gleam_stdlib:parse_int( Day@2 )} of {{ok, Year@3}, {ok, Month@3}, {ok, Day@3}} -> case new_date( Year@3, month_to_int( Month@3 ), Day@3 ) of {ok, Date@2} -> {{some, Date@2}, gleam@string:replace( Unconsumed@1, Content@1, <<""/utf8>> )}; _ -> {none, Unconsumed@1} end; {_, _, _} -> {none, Unconsumed@1} end; _ -> {none, Unconsumed@1} end end), {Offset@1, Unconsumed@3} = (case gleam@regexp:scan( Offset_re, Unconsumed@2 ) of [{match, Content@2, [{some, Hours}, {some, Minutes}]} | _] -> case {gleam_stdlib:parse_int( Hours ), gleam_stdlib:parse_int( Minutes )} of {{ok, Hour}, {ok, Minute}} -> case new_offset( (Hour * 60) + Minute ) of {ok, Offset} -> {{some, Offset}, gleam@string:replace( Unconsumed@2, Content@2, <<""/utf8>> )}; _ -> {none, Unconsumed@2} end; {_, _} -> {none, Unconsumed@2} end; _ -> {none, Unconsumed@2} end), {Offset@2, Unconsumed@4} = (case Offset@1 of {some, O} -> {{some, O}, Unconsumed@3}; none -> case gleam@regexp:scan( Offset_char_re, Unconsumed@3 ) of [{match, Content@3, _} | _] -> {{some, {offset, 0}}, gleam@string:replace( Unconsumed@3, Content@3, <<""/utf8>> )}; _ -> {none, Unconsumed@3} end end), {Time, _} = begin Scan_results = gleam@regexp:scan( Time_re, Unconsumed@4 ), Adj_hour = case Scan_results of [{match, _, [_, _, _, _, {some, <<"PM"/utf8>>}]} | _] -> fun( _capture ) -> adjust_12_hour_to_24_hour( _capture, false ) end; [{match, _, [_, _, _, _, {some, <<"pm"/utf8>>}]} | _] -> fun( _capture@1 ) -> adjust_12_hour_to_24_hour( _capture@1, false ) end; [{match, _, [_, _, _, _, {some, <<"AM"/utf8>>}]} | _] -> fun( _capture@2 ) -> adjust_12_hour_to_24_hour( _capture@2, true ) end; [{match, _, [_, _, _, _, {some, <<"am"/utf8>>}]} | _] -> fun( _capture@3 ) -> adjust_12_hour_to_24_hour( _capture@3, true ) end; _ -> fun( Hour@1 ) -> Hour@1 end end, case Scan_results of [{match, Content@4, [{some, H}, {some, M}, {some, S}, {some, D@1} | _]} | _] -> case {gleam_stdlib:parse_int( H ), gleam_stdlib:parse_int( M ), gleam_stdlib:parse_int( S )} of {{ok, Hour@2}, {ok, Minute@1}, {ok, Second}} -> case {string:length( D@1 ), gleam_stdlib:parse_int( D@1 )} of {3, {ok, Milli}} -> case begin _pipe@3 = Adj_hour( Hour@2 ), new_time_milli( _pipe@3, Minute@1, Second, Milli ) end of {ok, Date@4} -> {{some, Date@4}, gleam@string:replace( Unconsumed@4, Content@4, <<""/utf8>> )}; _ -> {none, Unconsumed@4} end; {6, {ok, Micro}} -> case begin _pipe@4 = Adj_hour( Hour@2 ), new_time_micro( _pipe@4, Minute@1, Second, Micro ) end of {ok, Date@5} -> {{some, Date@5}, gleam@string:replace( Unconsumed@4, Content@4, <<""/utf8>> )}; _ -> {none, Unconsumed@4} end; {_, _} -> {none, Unconsumed@4} end; {_, _, _} -> {none, Unconsumed@4} end; [{match, Content@5, [{some, H@1}, {some, M@1}, {some, S@1} | _]} | _] -> case {gleam_stdlib:parse_int( H@1 ), gleam_stdlib:parse_int( M@1 ), gleam_stdlib:parse_int( S@1 )} of {{ok, Hour@3}, {ok, Minute@2}, {ok, Second@1}} -> case begin _pipe@5 = Adj_hour( Hour@3 ), new_time( _pipe@5, Minute@2, Second@1 ) end of {ok, Date@6} -> {{some, Date@6}, gleam@string:replace( Unconsumed@4, Content@5, <<""/utf8>> )}; _ -> {none, Unconsumed@4} end; {_, _, _} -> {none, Unconsumed@4} end; [{match, Content@6, [{some, H@2}, {some, M@2} | _]} | _] -> case {gleam_stdlib:parse_int( H@2 ), gleam_stdlib:parse_int( M@2 )} of {{ok, Hour@4}, {ok, Minute@3}} -> case begin _pipe@6 = Adj_hour( Hour@4 ), new_time( _pipe@6, Minute@3, 0 ) end of {ok, Date@7} -> {{some, Date@7}, gleam@string:replace( Unconsumed@4, Content@6, <<""/utf8>> )}; _ -> {none, Unconsumed@4} end; {_, _} -> {none, Unconsumed@4} end; _ -> {none, Unconsumed@4} end end, {Date@3, Time, Offset@2} end ) end ) end ) end ) end ) end ) end ). -file("/home/john/Repos/tempo/src/tempo.gleam", 3609). -spec find_offset(list(datetime_part())) -> {ok, offset()} | {error, tempo@error:offset_parse_error()}. find_offset(Parts) -> gleam@result:'try'( begin _pipe = gleam@list:find_map(Parts, fun(P) -> case P of {offset_str, O} -> {ok, O}; _ -> {error, nil} end end), gleam@result:replace_error( _pipe, {offset_invalid_format, <<"Missing offset"/utf8>>} ) end, fun(Offset_str) -> offset_from_string(Offset_str) end ). -file("/home/john/Repos/tempo/src/tempo.gleam", 1010). -spec datetime_format(date_time(), date_time_format()) -> binary(). datetime_format(Datetime, Format) -> Format_str = get_datetime_format_str(Format), _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{1,2}|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"/utf8>>, function => <<"datetime_format"/utf8>>, line => 1013}) end, _pipe = gleam@regexp:scan(Re, Format_str), _pipe@1 = lists:reverse(_pipe), _pipe@5 = gleam@list:fold(_pipe@1, [], fun(Acc, Match) -> case Match of {match, Content, []} -> [begin _pipe@2 = Content, _pipe@3 = date_replace_format( _pipe@2, erlang:element(2, Datetime) ), _pipe@4 = time_replace_format( _pipe@3, erlang:element(3, Datetime) ), offset_replace_format( _pipe@4, erlang:element(4, Datetime) ) end | Acc]; {match, _, [{some, Sub}]} -> [Sub | Acc]; {match, Content@1, _} -> [Content@1 | Acc] end end), gleam@string:join(_pipe@5, <<""/utf8>>). -file("/home/john/Repos/tempo/src/tempo.gleam", 84). -spec format_utc(date_time_format()) -> binary(). format_utc(Format) -> _pipe = now(), _pipe@1 = instant_as_utc_datetime(_pipe), datetime_format(_pipe@1, Format). -file("/home/john/Repos/tempo/src/tempo.gleam", 96). -spec format_local(date_time_format()) -> binary(). format_local(Format) -> case Format of http -> format_utc(http); _ -> _pipe = now(), _pipe@1 = instant_as_local_datetime(_pipe), datetime_format(_pipe@1, Format) end. -file("/home/john/Repos/tempo/src/tempo.gleam", 1128). -spec datetime_subtract(date_time(), duration()) -> date_time(). datetime_subtract(Datetime, Duration_to_subtract) -> case Datetime of {date_time, Date, Time, Offset} -> {naive_date_time, New_date, New_time} = naive_datetime_subtract( {naive_date_time, Date, Time}, Duration_to_subtract ), {date_time, New_date, New_time, Offset}; {local_date_time, _, _, _, Tz} -> Utc_dt_sub = begin _pipe = datetime_to_utc(Datetime), datetime_subtract(_pipe, Duration_to_subtract) end, Offset@1 = begin _pipe@1 = Utc_dt_sub, _pipe@2 = datetime_drop_offset(_pipe@1), (erlang:element(3, Tz))(_pipe@2) end, {naive_date_time, Date@1, Time@1} = begin _pipe@3 = datetime_to_offset(Utc_dt_sub, Offset@1), datetime_drop_offset(_pipe@3) end, {local_date_time, Date@1, Time@1, Offset@1, Tz} end. -file("/home/john/Repos/tempo/src/tempo.gleam", 935). -spec datetime_to_offset(date_time(), offset()) -> date_time(). datetime_to_offset(Datetime, Offset) -> _pipe = Datetime, _pipe@1 = datetime_to_utc(_pipe), _pipe@2 = datetime_subtract(_pipe@1, offset_to_duration(Offset)), _pipe@3 = datetime_drop_offset(_pipe@2), naive_datetime_set_offset(_pipe@3, Offset). -file("/home/john/Repos/tempo/src/tempo.gleam", 1289). -spec naive_datetime_subtract(naive_date_time(), duration()) -> naive_date_time(). naive_datetime_subtract(Datetime, Duration_to_subtract) -> gleam@bool:lazy_guard( erlang:element(2, Duration_to_subtract) < 0, fun() -> _pipe = Datetime, naive_datetime_add(_pipe, duration_absolute(Duration_to_subtract)) end, fun() -> Days_to_sub = duration_as_days(Duration_to_subtract), Time_to_sub = duration_decrease( Duration_to_subtract, duration_days(Days_to_sub) ), New_time_as_micro = begin _pipe@1 = erlang:element(3, Datetime), _pipe@2 = time_to_duration(_pipe@1), _pipe@3 = duration_decrease(_pipe@2, Time_to_sub), duration_as_microseconds(_pipe@3) end, {New_time_as_micro@1, Days_to_sub@1} = case New_time_as_micro < 0 of true -> {New_time_as_micro + 86400000000, Days_to_sub + 1}; false -> {New_time_as_micro, Days_to_sub} end, Time_to_sub@1 = {duration, time_to_microseconds(erlang:element(3, Datetime)) - New_time_as_micro@1}, New_date = begin _pipe@4 = erlang:element(2, Datetime), date_subtract(_pipe@4, Days_to_sub@1) end, New_time = begin _pipe@5 = erlang:element(3, Datetime), time_subtract(_pipe@5, Time_to_sub@1) end, {naive_date_time, New_date, New_time} end ). -file("/home/john/Repos/tempo/src/tempo.gleam", 1246). -spec naive_datetime_add(naive_date_time(), duration()) -> naive_date_time(). naive_datetime_add(Datetime, Duration_to_add) -> gleam@bool:lazy_guard( erlang:element(2, Duration_to_add) < 0, fun() -> _pipe = Datetime, naive_datetime_subtract(_pipe, duration_absolute(Duration_to_add)) end, fun() -> Days_to_add = duration_as_days(Duration_to_add), Time_to_add = duration_decrease( Duration_to_add, duration_days(Days_to_add) ), New_time_as_micro = begin _pipe@1 = erlang:element(3, Datetime), _pipe@2 = time_to_duration(_pipe@1), _pipe@3 = duration_increase(_pipe@2, Time_to_add), duration_as_microseconds(_pipe@3) end, {New_time_as_micro@1, Days_to_add@1} = case New_time_as_micro >= 86400000000 of true -> {New_time_as_micro - 86400000000, Days_to_add + 1}; false -> {New_time_as_micro, Days_to_add} end, Time_to_add@1 = {duration, New_time_as_micro@1 - time_to_microseconds( erlang:element(3, Datetime) )}, New_date = begin _pipe@4 = erlang:element(2, Datetime), date_add(_pipe@4, Days_to_add@1) end, New_time = begin _pipe@5 = erlang:element(3, Datetime), time_add(_pipe@5, Time_to_add@1) end, {naive_date_time, New_date, New_time} end ). -file("/home/john/Repos/tempo/src/tempo.gleam", 1079). -spec datetime_apply_offset(date_time()) -> naive_date_time(). datetime_apply_offset(Datetime) -> Applied = begin _pipe = Datetime, _pipe@1 = datetime_drop_offset(_pipe), naive_datetime_add( _pipe@1, offset_to_duration(erlang:element(4, Datetime)) ) end, {naive_date_time, erlang:element(2, Applied), erlang:element(3, Applied)}. -file("/home/john/Repos/tempo/src/tempo.gleam", 928). -spec datetime_to_utc(date_time()) -> date_time(). datetime_to_utc(Datetime) -> _pipe = Datetime, _pipe@1 = datetime_apply_offset(_pipe), naive_datetime_set_offset(_pipe@1, {offset, 0}). -file("/home/john/Repos/tempo/src/tempo.gleam", 944). -spec datetime_to_tz(date_time(), time_zone_provider()) -> date_time(). datetime_to_tz(Datetime, Tz) -> Utc_dt = datetime_apply_offset(Datetime), Offset = (erlang:element(3, Tz))(Utc_dt), Naive = begin _pipe@1 = datetime_to_offset( begin _pipe = Utc_dt, naive_datetime_set_offset(_pipe, {offset, 0}) end, Offset ), datetime_drop_offset(_pipe@1) end, {local_date_time, erlang:element(2, Naive), erlang:element(3, Naive), Offset, Tz}. -file("/home/john/Repos/tempo/src/tempo.gleam", 1040). -spec datetime_compare(date_time(), date_time()) -> gleam@order:order(). datetime_compare(A, B) -> _pipe = datetime_apply_offset(A), naive_datetime_compare(_pipe, datetime_apply_offset(B)). -file("/home/john/Repos/tempo/src/tempo.gleam", 140). -spec compare(date_time()) -> gleam@order:order(). compare(Datetime) -> datetime_compare( begin _pipe = now(), instant_as_utc_datetime(_pipe) end, Datetime ). -file("/home/john/Repos/tempo/src/tempo.gleam", 1046). -spec datetime_is_earlier(date_time(), date_time()) -> boolean(). datetime_is_earlier(A, B) -> datetime_compare(A, B) =:= lt. -file("/home/john/Repos/tempo/src/tempo.gleam", 152). -spec is_earlier(date_time()) -> boolean(). is_earlier(Datetime) -> datetime_is_earlier( begin _pipe = now(), instant_as_utc_datetime(_pipe) end, Datetime ). -file("/home/john/Repos/tempo/src/tempo.gleam", 1051). -spec datetime_is_earlier_or_equal(date_time(), date_time()) -> boolean(). datetime_is_earlier_or_equal(A, B) -> (datetime_compare(A, B) =:= lt) orelse (datetime_compare(A, B) =:= eq). -file("/home/john/Repos/tempo/src/tempo.gleam", 165). -spec is_earlier_or_equal(date_time()) -> boolean(). is_earlier_or_equal(Datetime) -> datetime_is_earlier_or_equal( begin _pipe = now(), instant_as_utc_datetime(_pipe) end, Datetime ). -file("/home/john/Repos/tempo/src/tempo.gleam", 1056). -spec datetime_is_equal(date_time(), date_time()) -> boolean(). datetime_is_equal(A, B) -> datetime_compare(A, B) =:= eq. -file("/home/john/Repos/tempo/src/tempo.gleam", 176). -spec is_equal(date_time()) -> boolean(). is_equal(Datetime) -> datetime_is_equal( begin _pipe = now(), instant_as_utc_datetime(_pipe) end, Datetime ). -file("/home/john/Repos/tempo/src/tempo.gleam", 1061). -spec datetime_is_later_or_equal(date_time(), date_time()) -> boolean(). datetime_is_later_or_equal(A, B) -> (datetime_compare(A, B) =:= gt) orelse (datetime_compare(A, B) =:= eq). -file("/home/john/Repos/tempo/src/tempo.gleam", 201). -spec is_later_or_equal(date_time()) -> boolean(). is_later_or_equal(Datetime) -> datetime_is_later_or_equal( begin _pipe = now(), instant_as_utc_datetime(_pipe) end, Datetime ). -file("/home/john/Repos/tempo/src/tempo.gleam", 1066). -spec datetime_is_later(date_time(), date_time()) -> boolean(). datetime_is_later(A, B) -> datetime_compare(A, B) =:= gt. -file("/home/john/Repos/tempo/src/tempo.gleam", 188). -spec is_later(date_time()) -> boolean(). is_later(Datetime) -> datetime_is_later( begin _pipe = now(), instant_as_utc_datetime(_pipe) end, Datetime ). -file("/home/john/Repos/tempo/src/tempo.gleam", 1071). -spec datetime_difference(date_time(), date_time()) -> duration(). datetime_difference(A, B) -> naive_datetime_difference( datetime_apply_offset(A), datetime_apply_offset(B) ). -file("/home/john/Repos/tempo/src/tempo.gleam", 533). -spec difference(date_time()) -> duration(). difference(Start) -> _pipe = now(), _pipe@1 = instant_as_utc_datetime(_pipe), datetime_difference(Start, _pipe@1). -file("/home/john/Repos/tempo/src/tempo.gleam", 554). -spec since(date_time()) -> duration(). since(Start) -> case difference(Start) of {duration, Diff} when Diff > 0 -> {duration, Diff}; _ -> {duration, 0} end. -file("/home/john/Repos/tempo/src/tempo.gleam", 577). -spec until(date_time()) -> duration(). until(End) -> case begin _pipe = now(), _pipe@1 = instant_as_utc_datetime(_pipe), datetime_difference(_pipe@1, End) end of {duration, Diff} when Diff > 0 -> {duration, Diff}; _ -> {duration, 0} end. -file("/home/john/Repos/tempo/src/tempo.gleam", 1096). -spec datetime_add(date_time(), duration()) -> date_time(). datetime_add(Datetime, Duration_to_add) -> case Datetime of {date_time, Date, Time, Offset} -> {naive_date_time, New_date, New_time} = naive_datetime_add( {naive_date_time, Date, Time}, Duration_to_add ), {date_time, New_date, New_time, Offset}; {local_date_time, _, _, _, Tz} -> Utc_dt_added = begin _pipe = datetime_to_utc(Datetime), datetime_add(_pipe, Duration_to_add) end, Offset@1 = begin _pipe@1 = Utc_dt_added, _pipe@2 = datetime_drop_offset(_pipe@1), (erlang:element(3, Tz))(_pipe@2) end, {naive_date_time, Date@1, Time@1} = begin _pipe@3 = datetime_to_offset(Utc_dt_added, Offset@1), datetime_drop_offset(_pipe@3) end, {local_date_time, Date@1, Time@1, Offset@1, Tz} end. -file("/home/john/Repos/tempo/src/tempo.gleam", 2624). -spec period_new(date_time(), date_time()) -> period(). period_new(Start, End) -> {Start@1, End@1} = case begin _pipe = Start, datetime_is_earlier_or_equal(_pipe, End) end of true -> {Start, End}; false -> {End, Start} end, {date_time_period, Start@1, End@1}. -file("/home/john/Repos/tempo/src/tempo.gleam", 2682). -spec period_contains_datetime(period(), date_time()) -> boolean(). period_contains_datetime(Period, Datetime) -> case Period of {date_time_period, Start, End} -> begin _pipe = Datetime, datetime_is_later_or_equal(_pipe, Start) end andalso begin _pipe@1 = Datetime, datetime_is_earlier_or_equal(_pipe@1, End) end; _ -> period_contains_naive_datetime( Period, {naive_date_time, erlang:element(2, Datetime), erlang:element(3, Datetime)} ) end.