-module(tempo). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([datetime/2, 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, validate_offset/1, new_offset/1, offset_to_duration/1, date/3, date_get_year/1, date_get_month/1, date_get_day/1, month_from_int/1, month_from_short_string/1, month_from_long_string/1, month_to_int/1, date_compare/2, date_is_earlier_or_equal/2, month_year_to_int/1, month_next/1, month_prior/1, month_year_prior/1, month_year_next/1, is_leap_year/1, month_days_of/2, date_from_tuple/1, new_date/3, date_add/2, date_subtract/2, year_days/1, date_days_apart/2, time/6, time_get_hour/1, time_get_minute/1, time_get_second/1, time_get_nano/1, time_get_mono/1, time_get_unique/1, time_set_mono/3, validate_time/1, new_time/3, new_time_milli/4, new_time_micro/4, new_time_nano/4, adjust_12_hour_to_24_hour/2, time_to_nanoseconds/1, time_difference/2, time_from_nanoseconds/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, duration/1, duration_get_ns/1, time_add/2, time_subtract/2, duration_days/1, duration_increase/2, naive_datetime_difference/2, duration_decrease/2, duration_absolute/1, duration_as_days/1, duration_as_nanoseconds/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, accept_imprecision/1, error_on_imprecision/1, find_date/1, find_time/1, now_utc/0, now_monotonic/0, now_unique/0, now_monounique/0, consume_format/2, offset_from_string/1, parse_any/1, find_offset/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, datetime_is_earlier/2, datetime_is_earlier_or_equal/2, datetime_is_later_or_equal/2, datetime_add/2, period_new/2, period_contains_datetime/2]). -export_type([date_time/0, time_zone_provider/0, naive_date_time/0, offset/0, date/0, month_year/0, month/0, time/0, duration/0, period/0, offset_parse_error/0, time_parse_error/0, time_out_of_bounds_error/0, date_parse_error/0, date_out_of_bounds_error/0, date_time_out_of_bounds_error/0, date_time_parse_error/0, naive_date_time_out_of_bounds_error/0, naive_date_time_parse_error/0, naive_date_time_parse_any_error/0, date_time_parse_any_error/0, uncertain_conversion/1, datetime_part/0]). -opaque date_time() :: {date_time, naive_date_time(), offset()} | {local_date_time, naive_date_time(), offset(), time_zone_provider()}. -type time_zone_provider() :: {time_zone_provider, fun(() -> binary()), fun((naive_date_time()) -> offset())}. -opaque naive_date_time() :: {naive_date_time, date(), time()}. -opaque offset() :: {offset, integer()}. -opaque date() :: {date, integer(), month(), integer()}. -type month_year() :: {month_year, month(), integer()}. -type month() :: jan | feb | mar | apr | may | jun | jul | aug | sep | oct | nov | dec. -opaque time() :: {time, integer(), integer(), integer(), integer(), gleam@option:option(integer()), gleam@option:option(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 offset_parse_error() :: {offset_invalid_format, binary()} | offset_out_of_bounds. -type time_parse_error() :: {time_invalid_format, binary()} | {time_out_of_bounds, time_out_of_bounds_error()}. -type time_out_of_bounds_error() :: time_hour_out_of_bounds | time_minute_out_of_bounds | time_second_out_of_bounds | time_nano_second_out_of_bounds. -type date_parse_error() :: {date_invalid_format, binary()} | {date_out_of_bounds, date_out_of_bounds_error()}. -type date_out_of_bounds_error() :: date_day_out_of_bounds | date_month_out_of_bounds | date_year_out_of_bounds. -type date_time_out_of_bounds_error() :: {date_time_date_out_of_bounds, date_out_of_bounds_error()} | {date_time_time_out_of_bounds, time_out_of_bounds_error()} | date_time_offset_out_of_bounds. -type date_time_parse_error() :: date_time_invalid_format | {date_time_time_parse_error, time_parse_error()} | {date_time_date_parse_error, date_parse_error()} | {date_time_offset_parse_error, offset_parse_error()}. -type naive_date_time_out_of_bounds_error() :: {naive_date_time_date_out_of_bounds, date_out_of_bounds_error()} | {naive_date_time_time_out_of_bounds, time_out_of_bounds_error()}. -type naive_date_time_parse_error() :: naive_date_time_invalid_format | {naive_date_time_time_parse_error, time_parse_error()} | {naive_date_time_date_parse_error, date_parse_error()}. -type naive_date_time_parse_any_error() :: naive_date_time_missing_date | naive_date_time_missing_time. -type date_time_parse_any_error() :: date_time_missing_date | date_time_missing_time | date_time_missing_offset. -type uncertain_conversion(HCP) :: {precise, HCP} | {imprecise, HCP}. -type datetime_part() :: {year, integer()} | {month, integer()} | {day, integer()} | {hour, integer()} | {minute, integer()} | {second, integer()} | {millisecond, integer()} | {microsecond, integer()} | {nanosecond, integer()} | {offset_str, binary()} | {twelve_hour, integer()} | am_period | pm_period | passthrough. -file("/home/john/tempo/src/tempo.gleam", 51). -spec datetime(naive_date_time(), offset()) -> date_time(). datetime(Naive, Offset) -> {date_time, Naive, Offset}. -file("/home/john/tempo/src/tempo.gleam", 56). -spec datetime_get_naive(date_time()) -> naive_date_time(). datetime_get_naive(Datetime) -> erlang:element(2, Datetime). -file("/home/john/tempo/src/tempo.gleam", 61). -spec datetime_get_offset(date_time()) -> offset(). datetime_get_offset(Datetime) -> erlang:element(3, Datetime). -file("/home/john/tempo/src/tempo.gleam", 95). -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/tempo/src/tempo.gleam", 143). -spec datetime_drop_offset(date_time()) -> naive_date_time(). datetime_drop_offset(Datetime) -> erlang:element(2, Datetime). -file("/home/john/tempo/src/tempo.gleam", 213). -spec naive_datetime(date(), time()) -> naive_date_time(). naive_datetime(Date, Time) -> {naive_date_time, Date, Time}. -file("/home/john/tempo/src/tempo.gleam", 218). -spec naive_datetime_get_date(naive_date_time()) -> date(). naive_datetime_get_date(Naive_datetime) -> erlang:element(2, Naive_datetime). -file("/home/john/tempo/src/tempo.gleam", 223). -spec naive_datetime_get_time(naive_date_time()) -> time(). naive_datetime_get_time(Naive_datetime) -> erlang:element(3, Naive_datetime). -file("/home/john/tempo/src/tempo.gleam", 228). -spec naive_datetime_set_offset(naive_date_time(), offset()) -> date_time(). naive_datetime_set_offset(Datetime, Offset) -> {date_time, Datetime, Offset}. -file("/home/john/tempo/src/tempo.gleam", 378). -spec offset(integer()) -> offset(). offset(Minutes) -> {offset, Minutes}. -file("/home/john/tempo/src/tempo.gleam", 383). -spec offset_get_minutes(offset()) -> integer(). offset_get_minutes(Offset) -> erlang:element(2, Offset). -file("/home/john/tempo/src/tempo.gleam", 457). -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/tempo/src/tempo.gleam", 391). -spec new_offset(integer()) -> {ok, offset()} | {error, nil}. new_offset(Minutes) -> _pipe = {offset, Minutes}, validate_offset(_pipe). -file("/home/john/tempo/src/tempo.gleam", 466). -spec offset_to_duration(offset()) -> duration(). offset_to_duration(Offset) -> _pipe = - erlang:element(2, Offset) * 60000000000, {duration, _pipe}. -file("/home/john/tempo/src/tempo.gleam", 481). -spec date(integer(), month(), integer()) -> date(). date(Year, Month, Day) -> {date, Year, Month, Day}. -file("/home/john/tempo/src/tempo.gleam", 486). -spec date_get_year(date()) -> integer(). date_get_year(Date) -> erlang:element(2, Date). -file("/home/john/tempo/src/tempo.gleam", 491). -spec date_get_month(date()) -> month(). date_get_month(Date) -> erlang:element(3, Date). -file("/home/john/tempo/src/tempo.gleam", 496). -spec date_get_day(date()) -> integer(). date_get_day(Date) -> erlang:element(4, Date). -file("/home/john/tempo/src/tempo.gleam", 670). -spec calendar_years_apart(date(), date()) -> integer(). calendar_years_apart(Later, Earlier) -> erlang:element(2, Later) - erlang:element(2, Earlier). -file("/home/john/tempo/src/tempo.gleam", 728). -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/tempo/src/tempo.gleam", 747). -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/tempo/src/tempo.gleam", 766). -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/tempo/src/tempo.gleam", 785). -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/tempo/src/tempo.gleam", 675). -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/tempo/src/tempo.gleam", 695). -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/tempo/src/tempo.gleam", 803). -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/tempo/src/tempo.gleam", 833). -spec month_next(month()) -> month(). month_next(Month) -> case Month of jan -> feb; feb -> mar; mar -> apr; apr -> may; may -> jun; jun -> jul; jul -> aug; aug -> sep; sep -> oct; oct -> nov; nov -> dec; dec -> jan end. -file("/home/john/tempo/src/tempo.gleam", 859). -spec month_prior(month()) -> month(). month_prior(Month) -> case Month of jan -> dec; feb -> jan; mar -> feb; apr -> mar; may -> apr; jun -> may; jul -> jun; aug -> jul; sep -> aug; oct -> sep; nov -> oct; dec -> nov end. -file("/home/john/tempo/src/tempo.gleam", 851). -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}; Month -> {month_year, month_prior(Month), erlang:element(3, Month_year)} end. -file("/home/john/tempo/src/tempo.gleam", 877). -spec month_year_next(month_year()) -> month_year(). month_year_next(Month_year) -> case erlang:element(2, Month_year) of dec -> {month_year, jan, erlang:element(3, Month_year) + 1}; Month -> {month_year, month_next(Month), erlang:element(3, Month_year)} end. -file("/home/john/tempo/src/tempo.gleam", 889). -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/tempo/src/tempo.gleam", 808). -spec month_days_of(month(), integer()) -> integer(). month_days_of(Month, Year) -> case Month of jan -> 31; mar -> 31; may -> 31; jul -> 31; aug -> 31; oct -> 31; dec -> 31; _ -> case Month of apr -> 30; jun -> 30; sep -> 30; nov -> 30; _ -> case is_leap_year(Year) of true -> 29; false -> 28 end end end. -file("/home/john/tempo/src/tempo.gleam", 510). -spec date_from_tuple({integer(), integer(), integer()}) -> {ok, date()} | {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) 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} end; false -> {error, date_year_out_of_bounds} end end ). -file("/home/john/tempo/src/tempo.gleam", 501). -spec new_date(integer(), integer(), integer()) -> {ok, date()} | {error, date_out_of_bounds_error()}. new_date(Year, Month, Day) -> date_from_tuple({Year, Month, Day}). -file("/home/john/tempo/src/tempo.gleam", 532). -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_next(erlang:element(3, Date)), Year = case Next_month =:= jan of true -> (erlang:element(2, Date)) + 1; false -> erlang:element(2, Date) end, date_add( {date, Year, Next_month, 1}, (Days - Days_left_this_month) - 1 ) end. -file("/home/john/tempo/src/tempo.gleam", 550). -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_prior(erlang:element(3, Date)), Year = case Prior_month =:= dec of true -> (erlang:element(2, Date)) - 1; false -> erlang:element(2, Date) end, date_subtract( {date, Year, Prior_month, month_days_of(Prior_month, Year)}, Days - date_get_day(Date) ) end. -file("/home/john/tempo/src/tempo.gleam", 621). -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( begin _pipe@2 = From, _pipe@3 = date_get_month(_pipe@2), month_next(_pipe@3) end ), month_to_int( begin _pipe@4 = To, _pipe@5 = date_get_month(_pipe@4), month_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 => 640}) 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( begin _pipe@8 = To, _pipe@9 = date_get_month(_pipe@8), month_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 => 650}) 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( begin _pipe@13 = From, _pipe@14 = date_get_month( _pipe@13 ), month_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 => 660} ) 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/tempo/src/tempo.gleam", 905). -spec year_days(integer()) -> integer(). year_days(Year) -> case is_leap_year(Year) of true -> 366; false -> 365 end. -file("/home/john/tempo/src/tempo.gleam", 578). -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/tempo/src/tempo.gleam", 569). -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/tempo/src/tempo.gleam", 932). -spec time( integer(), integer(), integer(), integer(), gleam@option:option(integer()), gleam@option:option(integer()) ) -> time(). time(Hour, Minute, Second, Nanosecond, Monotonic, Unique) -> {time, Hour, Minute, Second, Nanosecond, Monotonic, Unique}. -file("/home/john/tempo/src/tempo.gleam", 944). -spec time_get_hour(time()) -> integer(). time_get_hour(Time) -> erlang:element(2, Time). -file("/home/john/tempo/src/tempo.gleam", 949). -spec time_get_minute(time()) -> integer(). time_get_minute(Time) -> erlang:element(3, Time). -file("/home/john/tempo/src/tempo.gleam", 954). -spec time_get_second(time()) -> integer(). time_get_second(Time) -> erlang:element(4, Time). -file("/home/john/tempo/src/tempo.gleam", 959). -spec time_get_nano(time()) -> integer(). time_get_nano(Time) -> erlang:element(5, Time). -file("/home/john/tempo/src/tempo.gleam", 964). -spec time_get_mono(time()) -> gleam@option:option(integer()). time_get_mono(Time) -> erlang:element(6, Time). -file("/home/john/tempo/src/tempo.gleam", 969). -spec time_get_unique(time()) -> gleam@option:option(integer()). time_get_unique(Time) -> erlang:element(7, Time). -file("/home/john/tempo/src/tempo.gleam", 974). -spec time_set_mono( time(), gleam@option:option(integer()), gleam@option:option(integer()) ) -> time(). time_set_mono(Time, Monotonic, Unique) -> {time, erlang:element(2, Time), erlang:element(3, Time), erlang:element(4, Time), erlang:element(5, Time), Monotonic, Unique}. -file("/home/john/tempo/src/tempo.gleam", 1031). -spec validate_time(time()) -> {ok, time()} | {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) =< 999999999 of true -> {ok, Time}; false -> {error, time_nano_second_out_of_bounds} 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}; {_, M, _} when (M > 59) orelse (M < 0) -> {error, time_minute_out_of_bounds}; {_, _, _} -> {error, time_hour_out_of_bounds} end end. -file("/home/john/tempo/src/tempo.gleam", 990). -spec new_time(integer(), integer(), integer()) -> {ok, time()} | {error, time_out_of_bounds_error()}. new_time(Hour, Minute, Second) -> _pipe = {time, Hour, Minute, Second, 0, none, none}, validate_time(_pipe). -file("/home/john/tempo/src/tempo.gleam", 999). -spec new_time_milli(integer(), integer(), integer(), integer()) -> {ok, time()} | {error, time_out_of_bounds_error()}. new_time_milli(Hour, Minute, Second, Millisecond) -> _pipe = {time, Hour, Minute, Second, Millisecond * 1000000, none, none}, validate_time(_pipe). -file("/home/john/tempo/src/tempo.gleam", 1010). -spec new_time_micro(integer(), integer(), integer(), integer()) -> {ok, time()} | {error, time_out_of_bounds_error()}. new_time_micro(Hour, Minute, Second, Microsecond) -> _pipe = {time, Hour, Minute, Second, Microsecond * 1000, none, none}, validate_time(_pipe). -file("/home/john/tempo/src/tempo.gleam", 1021). -spec new_time_nano(integer(), integer(), integer(), integer()) -> {ok, time()} | {error, time_out_of_bounds_error()}. new_time_nano(Hour, Minute, Second, Nanosecond) -> _pipe = {time, Hour, Minute, Second, Nanosecond, none, none}, validate_time(_pipe). -file("/home/john/tempo/src/tempo.gleam", 1068). -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/tempo/src/tempo.gleam", 1086). -spec time_to_nanoseconds(time()) -> integer(). time_to_nanoseconds(Time) -> (((erlang:element(2, Time) * 3600000000000) + (erlang:element(3, Time) * 60000000000)) + (erlang:element(4, Time) * 1000000000)) + erlang:element(5, Time). -file("/home/john/tempo/src/tempo.gleam", 1078). -spec time_difference(time(), time()) -> duration(). time_difference(A, B) -> case {erlang:element(6, A), erlang:element(6, B)} of {{some, Amns}, {some, Bmns}} -> _pipe = Bmns - Amns, {duration, _pipe}; {_, _} -> _pipe@1 = time_to_nanoseconds(B) - time_to_nanoseconds(A), {duration, _pipe@1} end. -file("/home/john/tempo/src/tempo.gleam", 1094). -spec time_from_nanoseconds(integer()) -> time(). time_from_nanoseconds(Nanoseconds) -> In_range_ns = case 86400000000000 of 0 -> 0; Gleam@denominator -> Nanoseconds rem Gleam@denominator end, Adj_ns = case In_range_ns < 0 of true -> In_range_ns + 86400000000000; false -> In_range_ns end, Hours = Adj_ns div 3600000000000, Minutes = (Adj_ns - (Hours * 3600000000000)) div 60000000000, Seconds = ((Adj_ns - (Hours * 3600000000000)) - (Minutes * 60000000000)) div 1000000000, Nanoseconds@1 = ((Adj_ns - (Hours * 3600000000000)) - (Minutes * 60000000000)) - (Seconds * 1000000000), {time, Hours, Minutes, Seconds, Nanoseconds@1, none, none}. -file("/home/john/tempo/src/tempo.gleam", 1123). -spec time_to_duration(time()) -> duration(). time_to_duration(Time) -> _pipe = time_to_nanoseconds(Time), {duration, _pipe}. -file("/home/john/tempo/src/tempo.gleam", 1128). -spec time_compare(time(), time()) -> gleam@order:order(). time_compare(A, B) -> case {erlang:element(7, A), erlang:element(7, B)} of {{some, Au}, {some, Bu}} -> gleam@int:compare(Au, Bu); {_, _} -> case {erlang:element(6, A), erlang:element(6, B)} of {{some, Amns}, {some, Bmns}} -> gleam@int:compare(Amns, Bmns); {_, _} -> 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 end end. -file("/home/john/tempo/src/tempo.gleam", 236). -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/tempo/src/tempo.gleam", 244). -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/tempo/src/tempo.gleam", 252). -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/tempo/src/tempo.gleam", 261). -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/tempo/src/tempo.gleam", 1207). -spec duration(integer()) -> duration(). duration(Nanoseconds) -> {duration, Nanoseconds}. -file("/home/john/tempo/src/tempo.gleam", 1212). -spec duration_get_ns(duration()) -> integer(). duration_get_ns(Duration) -> erlang:element(2, Duration). -file("/home/john/tempo/src/tempo.gleam", 1172). -spec time_add(time(), duration()) -> time(). time_add(A, B) -> New_time = begin _pipe = time_to_nanoseconds(A) + erlang:element(2, B), time_from_nanoseconds(_pipe) end, case erlang:element(6, A) of none -> New_time; {some, Mns} -> _pipe@1 = New_time, time_set_mono(_pipe@1, {some, Mns + duration_get_ns(B)}, none) end. -file("/home/john/tempo/src/tempo.gleam", 1182). -spec time_subtract(time(), duration()) -> time(). time_subtract(A, B) -> New_time = begin _pipe = time_to_nanoseconds(A) - erlang:element(2, B), time_from_nanoseconds(_pipe) end, case erlang:element(6, A) of none -> New_time; {some, Mns} -> _pipe@1 = New_time, time_set_mono(_pipe@1, {some, Mns - duration_get_ns(B)}, none) end. -file("/home/john/tempo/src/tempo.gleam", 1217). -spec duration_days(integer()) -> duration(). duration_days(Days) -> _pipe = Days, _pipe@1 = gtempo@internal:imprecise_days(_pipe), duration(_pipe@1). -file("/home/john/tempo/src/tempo.gleam", 1222). -spec duration_increase(duration(), duration()) -> duration(). duration_increase(A, B) -> {duration, erlang:element(2, A) + erlang:element(2, B)}. -file("/home/john/tempo/src/tempo.gleam", 270). -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/tempo/src/tempo.gleam", 1227). -spec duration_decrease(duration(), duration()) -> duration(). duration_decrease(A, B) -> {duration, erlang:element(2, A) - erlang:element(2, B)}. -file("/home/john/tempo/src/tempo.gleam", 1232). -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/tempo/src/tempo.gleam", 1240). -spec duration_as_days(duration()) -> integer(). duration_as_days(Duration) -> _pipe = erlang:element(2, Duration), gtempo@internal:as_days_imprecise(_pipe). -file("/home/john/tempo/src/tempo.gleam", 1245). -spec duration_as_nanoseconds(duration()) -> integer(). duration_as_nanoseconds(Duration) -> erlang:element(2, Duration). -file("/home/john/tempo/src/tempo.gleam", 1274). -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/tempo/src/tempo.gleam", 1286). -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/tempo/src/tempo.gleam", 1306). -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, none, none}, {time, 24, 0, 0, 0, none, none}}; {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, erlang:element(2, Start@2)), erlang:element(2, erlang:element(2, End@2)), erlang:element(3, erlang:element(2, Start@2)), erlang:element(3, erlang:element(2, End@2))} end. -file("/home/john/tempo/src/tempo.gleam", 1296). -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/tempo/src/tempo.gleam", 1345). -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/tempo/src/tempo.gleam", 1359). -spec period_comprising_dates(period()) -> gleam@yielder:yielder(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, erlang:element(2, Start@2)), erlang:element(2, erlang:element(2, End@2))} end, gleam@yielder:unfold( Start_date, fun(Date) -> case begin _pipe = Date, date_is_earlier_or_equal(_pipe, End_date) end of true -> {next, Date, begin _pipe@1 = Date, date_add(_pipe@1, 1) end}; false -> done end end ). -file("/home/john/tempo/src/tempo.gleam", 1375). -spec period_comprising_months(period()) -> gleam@yielder:yielder(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, gleam@yielder:unfold( {month_year, erlang:element(3, Start_date), erlang:element(2, Start_date)}, fun(Miy) -> case begin _pipe@6 = date( erlang:element(3, Miy), erlang:element(2, Miy), 1 ), date_is_earlier_or_equal(_pipe@6, End_date) end of true -> {next, Miy, {month_year, begin _pipe@7 = erlang:element(2, Miy), month_next(_pipe@7) end, case erlang:element(2, Miy) =:= dec of true -> erlang:element(3, Miy) + 1; false -> erlang:element(3, Miy) end}}; false -> done end end ). -file("/home/john/tempo/src/tempo.gleam", 1508). -spec accept_imprecision(uncertain_conversion(HFT)) -> HFT. accept_imprecision(Conv) -> case Conv of {precise, A} -> A; {imprecise, A@1} -> A@1 end. -file("/home/john/tempo/src/tempo.gleam", 1526). -spec error_on_imprecision(uncertain_conversion(HFV)) -> {ok, HFV} | {error, nil}. error_on_imprecision(Conv) -> case Conv of {precise, A} -> {ok, A}; {imprecise, _} -> {error, nil} end. -file("/home/john/tempo/src/tempo.gleam", 2064). -spec consume_one_or_two_digits(binary(), fun((integer()) -> HSK)) -> {ok, {HSK, 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/tempo/src/tempo.gleam", 2075). -spec consume_two_digits(binary(), fun((integer()) -> HTD)) -> {ok, {HTD, 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/tempo/src/tempo.gleam", 2082). -spec find_date(list(datetime_part())) -> {ok, date()} | {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(E) -> {date_out_of_bounds, E} end ) end ) end ) end ). -file("/home/john/tempo/src/tempo.gleam", 2118). -spec find_time(list(datetime_part())) -> {ok, time()} | {error, time_parse_error()}. find_time(Parts) -> gleam@result:'try'( (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)), 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 ), Nanosecond = gleam@list:find_map( Parts, fun(P@8) -> case P@8 of {nanosecond, N@2} -> {ok, N@2}; _ -> {error, nil} end end ), _pipe@5 = case {Nanosecond, Microsecond, Millisecond} of {{ok, Nano}, _, _} -> new_time_nano(Hour, Minute, Second, Nano); {_, {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(E) -> {time_out_of_bounds, E} end ) end ) end ). -file("/home/john/tempo/src/tempo.gleam", 2232). -spec result_guard({ok, IAK} | {error, any()}, IAN, fun((IAK) -> IAN)) -> IAN. result_guard(E, V, Run) -> case E of {error, _} -> V; {ok, Ok} -> Run(Ok) end. -file("/home/john/tempo/src/tempo.gleam", 2246). -spec now_utc() -> integer(). now_utc() -> tempo_ffi:now(). -file("/home/john/tempo/src/tempo.gleam", 2251). -spec now_monotonic() -> integer(). now_monotonic() -> tempo_ffi:now_monotonic(). -file("/home/john/tempo/src/tempo.gleam", 2256). -spec now_unique() -> integer(). now_unique() -> tempo_ffi:now_unique(). -file("/home/john/tempo/src/tempo.gleam", 2259). -spec now_monounique() -> {integer(), integer()}. now_monounique() -> {tempo_ffi:now_monotonic(), tempo_ffi:now_unique()}. -file("/home/john/tempo/src/tempo.gleam", 1861). -spec consume_part(binary(), binary()) -> {ok, {datetime_part(), binary()}} | {error, binary()}. consume_part(Fmt, Str) -> _pipe@16 = 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 ); <<"SSSSS"/utf8>> -> gleam@result:map( begin _pipe@4 = gleam@string:slice(Str, 0, 9), gleam_stdlib:parse_int(_pipe@4) end, fun(Nano) -> {{nanosecond, Nano}, gleam@string:drop_start(Str, 9)} end ); <<"z"/utf8>> -> gleam@result:try_recover( begin _pipe@5 = gleam@string:slice(Str, 0, 6), _pipe@7 = (fun(Offset) -> gleam@result:'try'( begin _pipe@6 = gleam@regexp:from_string( <<"[-+]\\d\\d:\\d\\d"/utf8>> ), gleam@result:replace_error(_pipe@6, nil) end, fun(Re) -> case gleam@regexp:check(Re, Offset) of true -> {ok, Offset}; false -> {error, nil} end end ) end)(_pipe@5), gleam@result:map( _pipe@7, fun(Offset@1) -> {{offset_str, Offset@1}, gleam@string:drop_start(Str, 6)} end ) end, fun(_) -> gleam@result:try_recover( begin _pipe@8 = gleam@string:slice(Str, 0, 5), _pipe@10 = (fun(Offset@2) -> gleam@result:'try'( begin _pipe@9 = gleam@regexp:from_string( <<"[-+]\\d\\d\\d\\d"/utf8>> ), gleam@result:replace_error(_pipe@9, 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@8), gleam@result:map( _pipe@10, fun(Offset@3) -> {{offset_str, Offset@3}, gleam@string:drop_start(Str, 5)} end ) end, fun(_) -> gleam@result:try_recover( begin _pipe@11 = gleam@string:slice(Str, 0, 3), _pipe@13 = (fun(Offset@4) -> gleam@result:'try'( begin _pipe@12 = gleam@regexp:from_string( <<"[-+]\\d\\d"/utf8>> ), gleam@result:replace_error( _pipe@12, 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@11), gleam@result:map( _pipe@13, fun(Offset@5) -> {{offset_str, Offset@5}, gleam@string:drop_start(Str, 3)} end ) end, fun(_) -> gleam@result:try_recover( begin _pipe@14 = gleam@string:slice( Str, 0, 1 ), _pipe@15 = (fun(Offset@6) -> case (Offset@6 =:= <<"Z"/utf8>>) orelse (Offset@6 =:= <<"z"/utf8>>) of true -> {ok, Offset@6}; false -> {error, nil} end end)(_pipe@14), gleam@result:map( _pipe@15, 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@16, fun(_) -> <<"Unable to parse directive "/utf8, Fmt/binary>> end ). -file("/home/john/tempo/src/tempo.gleam", 1825). -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 => 1826}) 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/tempo/src/tempo.gleam", 396). -spec offset_from_string(binary()) -> {ok, offset()} | {error, offset_parse_error()}. offset_from_string(Offset) -> gleam@result:'try'(case Offset of <<"Z"/utf8>> -> {ok, {offset, 0}}; <<"z"/utf8>> -> {ok, {offset, 0}}; _ -> gleam@result:'try'( case gleam@string:split(Offset, <<":"/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, <<"Invalid hour or minute length"/utf8>>}} end; _ -> case string:length(Offset) of 5 -> {ok, {gleam@string:slice(Offset, 0, 1), gleam@string:slice(Offset, 1, 2), gleam@string:slice(Offset, 3, 2)}}; 3 -> {ok, {gleam@string:slice(Offset, 0, 1), gleam@string:slice(Offset, 1, 2), <<"0"/utf8>>}}; 2 -> {ok, {gleam@string:slice(Offset, 0, 1), gleam@string:slice(Offset, 1, 1), <<"0"/utf8>>}}; _ -> {error, {offset_invalid_format, <<"Invalid offset length"/utf8>>}} 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, <<"Invalid sign or non-integer value"/utf8>>}} end end ) end, fun(Offset@1) -> _pipe = validate_offset(Offset@1), gleam@result:replace_error(_pipe, offset_out_of_bounds) end). -file("/home/john/tempo/src/tempo.gleam", 1578). -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; {9, {ok, Nano}} -> case begin _pipe@5 = Adj_hour( Hour@2 ), new_time_nano( _pipe@5, Minute@1, Second, Nano ) end of {ok, Date@6} -> {{some, Date@6}, 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@6 = Adj_hour( Hour@3 ), new_time( _pipe@6, Minute@2, Second@1 ) end of {ok, Date@7} -> {{some, Date@7}, 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@7 = Adj_hour( Hour@4 ), new_time( _pipe@7, Minute@3, 0 ) end of {ok, Date@8} -> {{some, Date@8}, 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/tempo/src/tempo.gleam", 2218). -spec find_offset(list(datetime_part())) -> {ok, offset()} | {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/tempo/src/tempo.gleam", 175). -spec datetime_subtract(date_time(), duration()) -> date_time(). datetime_subtract(Datetime, Duration_to_subtract) -> case Datetime of {date_time, Naive, Offset} -> {date_time, naive_datetime_subtract(Naive, Duration_to_subtract), 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@1 = begin _pipe@3 = datetime_to_offset(Utc_dt_sub, Offset@1), datetime_drop_offset(_pipe@3) end, {local_date_time, Naive@1, Offset@1, Tz} end. -file("/home/john/tempo/src/tempo.gleam", 73). -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/tempo/src/tempo.gleam", 320). -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_ns = 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_nanoseconds(_pipe@3) end, {New_time_as_ns@1, Days_to_sub@1} = case New_time_as_ns < 0 of true -> {New_time_as_ns + 86400000000000, Days_to_sub + 1}; false -> {New_time_as_ns, Days_to_sub} end, Time_to_sub@1 = {duration, time_to_nanoseconds(erlang:element(3, Datetime)) - New_time_as_ns@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/tempo/src/tempo.gleam", 280). -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_ns = 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_nanoseconds(_pipe@3) end, {New_time_as_ns@1, Days_to_add@1} = case New_time_as_ns >= 86400000000000 of true -> {New_time_as_ns - 86400000000000, Days_to_add + 1}; false -> {New_time_as_ns, Days_to_add} end, Time_to_add@1 = {duration, New_time_as_ns@1 - time_to_nanoseconds( 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/tempo/src/tempo.gleam", 124). -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(3, Datetime)) ) end, {naive_date_time, erlang:element(2, Applied), erlang:setelement( 7, erlang:setelement( 6, (erlang:element(3, Applied)), erlang:element( 6, erlang:element(3, erlang:element(2, Datetime)) ) ), erlang:element(7, erlang:element(3, erlang:element(2, Datetime))) )}. -file("/home/john/tempo/src/tempo.gleam", 66). -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/tempo/src/tempo.gleam", 82). -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, Naive, Offset, Tz}. -file("/home/john/tempo/src/tempo.gleam", 103). -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/tempo/src/tempo.gleam", 109). -spec datetime_is_earlier(date_time(), date_time()) -> boolean(). datetime_is_earlier(A, B) -> datetime_compare(A, B) =:= lt. -file("/home/john/tempo/src/tempo.gleam", 114). -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/tempo/src/tempo.gleam", 119). -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/tempo/src/tempo.gleam", 148). -spec datetime_add(date_time(), duration()) -> date_time(). datetime_add(Datetime, Duration_to_add) -> case Datetime of {date_time, Naive, Offset} -> {date_time, naive_datetime_add(Naive, Duration_to_add), 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@1 = begin _pipe@3 = datetime_to_offset(Utc_dt_added, Offset@1), datetime_drop_offset(_pipe@3) end, {local_date_time, Naive@1, Offset@1, Tz} end. -file("/home/john/tempo/src/tempo.gleam", 1264). -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/tempo/src/tempo.gleam", 1332). -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, erlang:element(2, Datetime)) end.