-module(tempo). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/tempo.gleam"). -export([now_unique_ffi/0, now_monotonic_ffi/0, offset_local_minutes/0, offset_local_micro/0, now_utc_ffi/0, now/0, time_from_microseconds/1, time_from_unix_micro/1, date_from_unix_micro/1, duration_get_microseconds/1, now_adjusted/1, offset_get_minutes/1, offset_to_string/1, time_get_micro/1, time_get_second/1, time_get_minute/1, time_get_hour/1, time_replace_format/2, date_to_day_of_week_number_us_convention/1, month_to_long_string/1, month_to_short_string/1, month_to_int/1, is_leap_year/1, month_year_days_of/1, month_days_of/2, date_to_rata_die/1, date_get_year/1, month_from_int/1, date_to_calendar_date/1, date_replace_format/2, tokenise_format/1, get_datetime_format_str/1, datetime_format/2, instant_as_utc_time/1, instant_as_utc_date/1, instant_as_utc_datetime/1, format_utc/1, instant_as_local_time/1, instant_as_local_date/1, instant_as_local_datetime/1, format_local/1, duration_seconds_and_nanoseconds/2, duration_absolute/1, duration_microseconds/1, instant_difference/2, instant_since/1, instant_since_formatted/1, offset_to_duration/1, time_to_microseconds/1, time_subtract/2, date_subtract/2, duration_as_microseconds/1, duration_inverse/1, duration_decrease/2, time_to_duration/1, duration_days/1, duration_as_days/1, time_add/2, date_add/2, duration_increase/2, duration_is_positive/1, naive_datetime_add/2, naive_datetime_subtract/2, datetime_drop_offset/1, datetime_apply_offset/1, time_compare/2, date_compare/2, naive_datetime_compare/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/2, is_later/1, datetime_is_later_or_equal/2, is_later_or_equal/1, compare_utc_date/1, compare_local_date/1, date_is_earlier/2, is_utc_date_earlier/1, is_local_date_earlier/1, date_is_earlier_or_equal/2, is_utc_date_earlier_or_equal/1, is_local_date_earlier_or_equal/1, date_is_equal/2, is_utc_date_equal/1, is_local_date_equal/1, date_is_later/2, is_utc_date_later/1, is_local_date_later/1, date_is_later_or_equal/2, is_utc_date_later_or_equal/1, is_local_date_later_or_equal/1, compare_utc_time/1, compare_local_time/1, time_is_earlier/2, is_utc_time_earlier/1, is_local_time_earlier/1, time_is_earlier_or_equal/2, is_utc_time_earlier_or_equal/1, is_local_time_earlier_or_equal/1, time_is_equal/2, is_utc_time_equal/1, is_local_time_equal/1, time_is_later/2, is_utc_time_later/1, is_local_time_later/1, time_is_later_or_equal/2, is_utc_time_later_or_equal/1, is_local_time_later_or_equal/1, time_difference/2, date_days_apart/2, naive_datetime_difference/2, datetime_difference/2, difference/1, duration_clamp_to_zero/1, since/1, until/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, sleep_ffi/1, sleep/1, instant_get_unique/1, instant_as_unix_seconds/1, instant_as_unix_milli/1, instant_as_unix_micro/1, time_to_parts/1, time_to_string/1, date_to_string/1, naive_datetime_to_string/1, datetime_to_string/1, instant_to_utc_string/1, instant_to_local_string/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, datetime/3, datetime_get_naive/1, datetime_get_offset/1, naive_datetime_set_offset/2, datetime_to_utc/1, datetime_add/2, datetime_to_offset/2, datetime_to_tz/2, datetime_get_tz/1, date_to_unix_micro/1, datetime_to_unix_micro/1, datetime_subtract/2, naive_datetime/2, naive_datetime_get_date/1, naive_datetime_get_time/1, naive_datetime_is_earlier/2, naive_datetime_is_earlier_or_equal/2, naive_datetime_is_later_or_equal/2, offset/1, validate_offset/1, duration_as_mintues/1, new_offset/1, offset_from_string/1, date/1, date_get_unix_days/1, date_from_rata_die/1, date_calendar_to_unix_days/1, date_from_calendar_date/1, date_get_month_year/1, date_get_month/1, date_get_day/1, date_from_tuple/1, new_date/3, date_from_unix_seconds/1, date_from_unix_milli/1, date_calendar_from_unix_seconds/1, date_to_unix_seconds/1, date_to_unix_milli/1, month_from_short_string/1, month_from_long_string/1, month_year_to_int/1, month_year_prior/1, month_year_next/1, year_days/1, time/4, validate_time/4, new_time/3, new_time_milli/4, new_time_micro/4, time_to_calendar_time_of_day/1, adjust_12_hour_to_24_hour/2, duration_minutes/1, period_new/2, 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_contains_datetime/2, period_comprising_dates/1, period_comprising_months/1, get_naive_datetime_format_str/1, get_time_format_str/1, get_date_format_str/1, parse_any/1, consume_format/2, find_date/1, find_time/1, find_offset/1, freeze_time_ffi/2, unfreeze_time_ffi/0, set_reference_time_ffi/3, unset_reference_time_ffi/0, set_sleep_warp_ffi/1, add_warp_time_ffi/1, reset_warp_time_ffi/0]). -export_type([instant/0, date_time/0, time_zone_provider/0, naive_date_time/0, offset/0, date/0, month_year/0, time/0, period/0, date_time_format/0, naive_date_time_format/0, date_format/0, time_format/0, locale/0, format_token/0, matched_time/0, datetime_part/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC( " The main module of this package. Contains most package types and general\n" " purpose functions.\n" " Look in specific modules for more functionality!\n" ). -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()}. -type month_year() :: {month_year, gleam@time@calendar:month(), integer()}. -opaque time() :: {time_of_day, integer()} | last_instant_of_day | {end_of_day_leap_second, 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() :: i_s_o8601_seconds | i_s_o8601_milli | i_s_o8601_micro | h_t_t_p | {custom, binary()} | {custom_localised, binary(), locale()} | {date_format, date_format()} | {time_format, time_format()}. -type naive_date_time_format() :: naive_i_s_o8601_seconds | naive_i_s_o8601_milli | naive_i_s_o8601_micro | {custom_naive, binary()} | {custom_naive_localised, binary(), locale()} | {naive_date_format, date_format()} | {naive_time_format, time_format()}. -type date_format() :: i_s_o8601_date | {custom_date, binary()} | {custom_date_localised, binary(), locale()}. -type time_format() :: i_s_o8601_time_seconds | i_s_o8601_time_milli | i_s_o8601_time_micro | {custom_time, binary()} | {custom_time_localised, binary(), locale()}. -type locale() :: any(). -type format_token() :: {directive, binary()} | {escaped, binary()}. -type matched_time() :: {matched_time, integer(), integer(), gleam@option:option(integer()), gleam@option:option({integer(), integer()}), gleam@option:option(boolean())}. -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()} | a_m_period | p_m_period | passthrough. -file("src/tempo.gleam", 4019). ?DOC(false). -spec now_unique_ffi() -> integer(). now_unique_ffi() -> tempo_ffi:now_unique(). -file("src/tempo.gleam", 4014). ?DOC(false). -spec now_monotonic_ffi() -> integer(). now_monotonic_ffi() -> tempo_ffi:now_monotonic(). -file("src/tempo.gleam", 4029). ?DOC(false). -spec offset_local_minutes() -> integer(). offset_local_minutes() -> tempo_ffi:local_offset(). -file("src/tempo.gleam", 4022). ?DOC(false). -spec offset_local_micro() -> integer(). offset_local_micro() -> tempo_ffi:local_offset() * 60000000. -file("src/tempo.gleam", 4009). ?DOC(false). -spec now_utc_ffi() -> integer(). now_utc_ffi() -> tempo_ffi:now(). -file("src/tempo.gleam", 44). ?DOC(false). -spec now() -> instant(). now() -> {instant, tempo_ffi:now(), offset_local_micro(), tempo_ffi:now_monotonic(), tempo_ffi:now_unique()}. -file("src/tempo.gleam", 2141). ?DOC(false). -spec time_from_microseconds(integer()) -> time(). time_from_microseconds(Microseconds) -> {time_of_day, Microseconds}. -file("src/tempo.gleam", 2497). ?DOC(false). -spec time_from_unix_micro(integer()) -> time(). time_from_unix_micro(Unix_ts) -> time_from_microseconds(case 86400000000 of 0 -> 0; Gleam@denominator -> Unix_ts rem Gleam@denominator end). -file("src/tempo.gleam", 1544). ?DOC(false). -spec date_from_unix_micro(integer()) -> date(). date_from_unix_micro(Unix_micro) -> {date, case 86400000000 of 0 -> 0; Gleam@denominator -> Unix_micro div Gleam@denominator end}. -file("src/tempo.gleam", 2582). ?DOC(false). -spec duration_get_microseconds(gleam@time@duration:duration()) -> integer(). duration_get_microseconds(Duration) -> {Seconds, Nanoseconds} = gleam@time@duration:to_seconds_and_nanoseconds( Duration ), (Seconds * 1000000) + (Nanoseconds div 1000). -file("src/tempo.gleam", 68). ?DOC(false). -spec now_adjusted(gleam@time@duration:duration()) -> date_time(). now_adjusted(Duration) -> New_ts = erlang:element(2, now()) + duration_get_microseconds(Duration), {date_time, date_from_unix_micro(New_ts), time_from_unix_micro(New_ts), {offset, 0}}. -file("src/tempo.gleam", 1343). ?DOC(false). -spec offset_get_minutes(offset()) -> integer(). offset_get_minutes(Offset) -> erlang:element(2, Offset). -file("src/tempo.gleam", 1376). ?DOC(false). -spec offset_to_string(offset()) -> binary(). offset_to_string(Offset) -> Is_negative = offset_get_minutes(Offset) < 0, Hours = case offset_get_minutes(Offset) div 60 of H when H < 0 -> - H; H@1 -> 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>>; {true, 0, M@2} -> <<"-00:"/utf8, (begin _pipe = erlang:integer_to_binary(M@2), gleam@string:pad_start(_pipe, 2, <<"0"/utf8>>) end)/binary>>; {false, 0, M@3} -> <<"+00:"/utf8, (begin _pipe@1 = erlang:integer_to_binary(M@3), gleam@string:pad_start(_pipe@1, 2, <<"0"/utf8>>) end)/binary>>; {true, H@2, M@4} -> <<<<<<"-"/utf8, (begin _pipe@2 = erlang:integer_to_binary(H@2), gleam@string:pad_start(_pipe@2, 2, <<"0"/utf8>>) end)/binary>>/binary, ":"/utf8>>/binary, (begin _pipe@3 = erlang:integer_to_binary(M@4), gleam@string:pad_start(_pipe@3, 2, <<"0"/utf8>>) end)/binary>>; {false, H@3, M@5} -> <<<<<<"+"/utf8, (begin _pipe@4 = erlang:integer_to_binary(H@3), gleam@string:pad_start(_pipe@4, 2, <<"0"/utf8>>) end)/binary>>/binary, ":"/utf8>>/binary, (begin _pipe@5 = erlang:integer_to_binary(M@5), gleam@string:pad_start(_pipe@5, 2, <<"0"/utf8>>) end)/binary>> end. -file("src/tempo.gleam", 1424). -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("src/tempo.gleam", 2126). ?DOC( " We really only want to normalise on the way out of the time type\n" " representation (like displaying a time) to preserve correct comparibility.\n" ). -spec time_normalise(time()) -> time(). time_normalise(Time) -> case Time of {time_of_day, Microseconds} when Microseconds < 0 -> {time_of_day, 86400000000 + (case 86400000000 of 0 -> 0; Gleam@denominator -> Microseconds rem Gleam@denominator end)}; {time_of_day, Microseconds@1} when Microseconds@1 >= 86400000000 -> {time_of_day, case 86400000000 of 0 -> 0; Gleam@denominator@1 -> Microseconds@1 rem Gleam@denominator@1 end}; _ -> Time end. -file("src/tempo.gleam", 2193). ?DOC(false). -spec time_get_micro(time()) -> integer(). time_get_micro(Time) -> case time_normalise(Time) of {time_of_day, Microseconds} -> Hour = case 3600000000 of 0 -> 0; Gleam@denominator -> Microseconds div Gleam@denominator end, Minute = case 60000000 of 0 -> 0; Gleam@denominator@1 -> (Microseconds - (Hour * 3600000000)) div Gleam@denominator@1 end, Second = case 1000000 of 0 -> 0; Gleam@denominator@2 -> ((Microseconds - (Hour * 3600000000)) - (Minute * 60000000)) div Gleam@denominator@2 end, ((Microseconds - (Hour * 3600000000)) - (Minute * 60000000)) - (Second * 1000000); last_instant_of_day -> 0; {end_of_day_leap_second, Microsecond} -> Microsecond end. -file("src/tempo.gleam", 2169). ?DOC(false). -spec time_get_second(time()) -> integer(). time_get_second(Time) -> case time_normalise(Time) of {time_of_day, Microseconds} -> Hour = case 3600000000 of 0 -> 0; Gleam@denominator -> Microseconds div Gleam@denominator end, Minute = case 60000000 of 0 -> 0; Gleam@denominator@1 -> (Microseconds - (Hour * 3600000000)) div Gleam@denominator@1 end, case 1000000 of 0 -> 0; Gleam@denominator@2 -> ((Microseconds - (Hour * 3600000000)) - (Minute * 60000000)) div Gleam@denominator@2 end; last_instant_of_day -> 0; {end_of_day_leap_second, _} -> 60 end. -file("src/tempo.gleam", 2155). ?DOC(false). -spec time_get_minute(time()) -> integer(). time_get_minute(Time) -> case time_normalise(Time) of {time_of_day, Microseconds} -> Hour = case 3600000000 of 0 -> 0; Gleam@denominator -> Microseconds div Gleam@denominator end, case 60000000 of 0 -> 0; Gleam@denominator@1 -> (Microseconds - (Hour * 3600000000)) div Gleam@denominator@1 end; last_instant_of_day -> 0; {end_of_day_leap_second, _} -> 59 end. -file("src/tempo.gleam", 2146). ?DOC(false). -spec time_get_hour(time()) -> integer(). time_get_hour(Time) -> case time_normalise(Time) of {time_of_day, Microseconds} -> case 3600000000 of 0 -> 0; Gleam@denominator -> Microseconds div Gleam@denominator end; last_instant_of_day -> 24; {end_of_day_leap_second, _} -> 23 end. -file("src/tempo.gleam", 2382). ?DOC(false). -spec time_replace_format(binary(), time()) -> binary(). time_replace_format(Content, Time) -> case Content of <<"H"/utf8>> -> _pipe = time_get_hour(Time), erlang:integer_to_binary(_pipe); <<"HH"/utf8>> -> _pipe@1 = time_get_hour(Time), _pipe@2 = erlang:integer_to_binary(_pipe@1), gleam@string:pad_start(_pipe@2, 2, <<"0"/utf8>>); <<"h"/utf8>> -> _pipe@3 = case time_get_hour(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 time_get_hour(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 time_get_hour(Time) >= 12 of true -> <<"pm"/utf8>>; false -> <<"am"/utf8>> end; <<"A"/utf8>> -> case time_get_hour(Time) >= 12 of true -> <<"PM"/utf8>>; false -> <<"AM"/utf8>> end; <<"m"/utf8>> -> _pipe@6 = time_get_minute(Time), erlang:integer_to_binary(_pipe@6); <<"mm"/utf8>> -> _pipe@7 = time_get_minute(Time), _pipe@8 = erlang:integer_to_binary(_pipe@7), gleam@string:pad_start(_pipe@8, 2, <<"0"/utf8>>); <<"s"/utf8>> -> _pipe@9 = time_get_second(Time), erlang:integer_to_binary(_pipe@9); <<"ss"/utf8>> -> _pipe@10 = time_get_second(Time), _pipe@11 = erlang:integer_to_binary(_pipe@10), gleam@string:pad_start(_pipe@11, 2, <<"0"/utf8>>); <<"SSS"/utf8>> -> _pipe@12 = (time_get_micro(Time) div 1000), _pipe@13 = erlang:integer_to_binary(_pipe@12), gleam@string:pad_start(_pipe@13, 3, <<"0"/utf8>>); <<"SSSS"/utf8>> -> _pipe@14 = (time_get_micro(Time)), _pipe@15 = erlang:integer_to_binary(_pipe@14), gleam@string:pad_start(_pipe@15, 6, <<"0"/utf8>>); _ -> Content end. -file("src/tempo.gleam", 1641). ?DOC(false). -spec date_to_day_of_week_number_us_convention(date()) -> integer(). date_to_day_of_week_number_us_convention(Date) -> case gleam@int:modulo(erlang:element(2, Date) + 4, 7) of {ok, Val} -> Val; {error, nil} -> erlang:error(#{gleam_error => panic, message => <<"Invalid int modulo operation"/utf8>>, file => <>, module => <<"tempo"/utf8>>, function => <<"date_to_day_of_week_number_us_convention"/utf8>>, line => 1644}) end. -file("src/tempo.gleam", 1627). -spec date_to_day_of_week_long(date()) -> binary(). date_to_day_of_week_long(Date) -> case date_to_day_of_week_number_us_convention(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>>, file => <>, module => <<"tempo"/utf8>>, function => <<"date_to_day_of_week_long"/utf8>>, line => 1636}) end. -file("src/tempo.gleam", 1614). -spec date_to_day_of_week_short(date()) -> binary(). date_to_day_of_week_short(Date) -> case date_to_day_of_week_number_us_convention(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>>, file => <>, module => <<"tempo"/utf8>>, function => <<"date_to_day_of_week_short"/utf8>>, line => 1623}) end. -file("src/tempo.gleam", 1960). ?DOC(false). -spec month_to_long_string(gleam@time@calendar:month()) -> binary(). month_to_long_string(Month) -> case Month of january -> <<"January"/utf8>>; february -> <<"February"/utf8>>; march -> <<"March"/utf8>>; april -> <<"April"/utf8>>; may -> <<"May"/utf8>>; june -> <<"June"/utf8>>; july -> <<"July"/utf8>>; august -> <<"August"/utf8>>; september -> <<"September"/utf8>>; october -> <<"October"/utf8>>; november -> <<"November"/utf8>>; december -> <<"December"/utf8>> end. -file("src/tempo.gleam", 1942). ?DOC(false). -spec month_to_short_string(gleam@time@calendar:month()) -> binary(). month_to_short_string(Month) -> case Month of january -> <<"Jan"/utf8>>; february -> <<"Feb"/utf8>>; march -> <<"Mar"/utf8>>; april -> <<"Apr"/utf8>>; may -> <<"May"/utf8>>; june -> <<"Jun"/utf8>>; july -> <<"Jul"/utf8>>; august -> <<"Aug"/utf8>>; september -> <<"Sep"/utf8>>; october -> <<"Oct"/utf8>>; november -> <<"Nov"/utf8>>; december -> <<"Dec"/utf8>> end. -file("src/tempo.gleam", 1924). ?DOC(false). -spec month_to_int(gleam@time@calendar:month()) -> integer(). month_to_int(Month) -> case Month of january -> 1; february -> 2; march -> 3; april -> 4; may -> 5; june -> 6; july -> 7; august -> 8; september -> 9; october -> 10; november -> 11; december -> 12 end. -file("src/tempo.gleam", 2059). ?DOC(false). -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("src/tempo.gleam", 2033). ?DOC(false). -spec month_year_days_of(month_year()) -> integer(). month_year_days_of(My) -> case erlang:element(2, My) of january -> 31; february -> case is_leap_year(erlang:element(3, My)) of true -> 29; false -> 28 end; march -> 31; april -> 30; may -> 31; june -> 30; july -> 31; august -> 31; september -> 30; october -> 31; november -> 30; december -> 31 end. -file("src/tempo.gleam", 1978). ?DOC(false). -spec month_days_of(gleam@time@calendar:month(), integer()) -> integer(). month_days_of(Month, Year) -> month_year_days_of({month_year, Month, Year}). -file("src/tempo.gleam", 1721). -spec do_calculate_rata_die(integer(), gleam@time@calendar:month(), integer()) -> gleam@time@calendar:date(). do_calculate_rata_die(Year, Month, Ordinal_day) -> Days_in_month = month_days_of(Month, Year), case (month_to_int(Month) < 12) andalso (Ordinal_day > Days_in_month) of true -> do_calculate_rata_die(Year, case Month of january -> february; february -> march; march -> april; april -> may; may -> june; june -> july; july -> august; august -> september; september -> october; october -> november; _ -> december end, Ordinal_day - Days_in_month); false -> {date, Year, Month, Ordinal_day} end. -file("src/tempo.gleam", 1852). -spec date_days_before_year(integer()) -> integer(). date_days_before_year(Year1) -> Year = Year1 - 1, Leap_years = (gtempo@internal:floor_div(Year, 4) - gtempo@internal:floor_div( Year, 100 )) + gtempo@internal:floor_div(Year, 400), (365 * Year) + Leap_years. -file("src/tempo.gleam", 1799). -spec date_to_rata_die(date()) -> integer(). date_to_rata_die(Date) -> erlang:element(2, Date) + 719163. -file("src/tempo.gleam", 1489). ?DOC(false). -spec date_get_year(date()) -> integer(). date_get_year(Date) -> Rd = date_to_rata_die(Date), {N400, R400} = gtempo@internal:div_with_remainder(Rd, 146097), {N100, R100} = gtempo@internal:div_with_remainder(R400, 36524), {N4, R4} = gtempo@internal:div_with_remainder(R100, 1461), {N1, R1} = gtempo@internal:div_with_remainder(R4, 365), N = case R1 =:= 0 of true -> 0; false -> 1 end, ((((N400 * 400) + (N100 * 100)) + (N4 * 4)) + N1) + N. -file("src/tempo.gleam", 1867). ?DOC(false). -spec month_from_int(integer()) -> {ok, gleam@time@calendar:month()} | {error, nil}. month_from_int(Month) -> case Month of 1 -> {ok, january}; 2 -> {ok, february}; 3 -> {ok, march}; 4 -> {ok, april}; 5 -> {ok, may}; 6 -> {ok, june}; 7 -> {ok, july}; 8 -> {ok, august}; 9 -> {ok, september}; 10 -> {ok, october}; 11 -> {ok, november}; 12 -> {ok, december}; _ -> {error, nil} end. -file("src/tempo.gleam", 1676). -spec date_calendar_from_unix_days(integer()) -> gleam@time@calendar:date(). date_calendar_from_unix_days(Unix_days) -> case Unix_days >= 0 of true -> Z = Unix_days + 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, Month@1 = case month_from_int(M) of {ok, Month} -> Month; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"tempo"/utf8>>, function => <<"date_calendar_from_unix_days"/utf8>>, line => 1704, value => _assert_fail, start => 45570, 'end' => 45610, pattern_start => 45581, pattern_end => 45590}) end, {date, Y@1, Month@1, D}; false -> Rata_die = begin _pipe = {date, Unix_days}, date_to_rata_die(_pipe) end, Ordinal_year = begin _pipe@1 = {date, Unix_days}, date_get_year(_pipe@1) end, Ordinal_date = Rata_die - date_days_before_year(Ordinal_year), do_calculate_rata_die(Ordinal_year, january, Ordinal_date) end. -file("src/tempo.gleam", 1473). ?DOC(false). -spec date_to_calendar_date(date()) -> gleam@time@calendar:date(). date_to_calendar_date(Date) -> date_calendar_from_unix_days(erlang:element(2, Date)). -file("src/tempo.gleam", 1565). ?DOC(false). -spec date_replace_format(binary(), date()) -> binary(). date_replace_format(Content, Date) -> Calendar_date = date_to_calendar_date(Date), case Content of <<"YY"/utf8>> -> _pipe = erlang:element(2, Calendar_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, Calendar_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, Calendar_date), _pipe@6 = month_to_int(_pipe@5), erlang:integer_to_binary(_pipe@6); <<"MM"/utf8>> -> _pipe@7 = erlang:element(3, Calendar_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, Calendar_date), month_to_short_string(_pipe@10); <<"MMMM"/utf8>> -> _pipe@11 = erlang:element(3, Calendar_date), month_to_long_string(_pipe@11); <<"D"/utf8>> -> _pipe@12 = erlang:element(4, Calendar_date), erlang:integer_to_binary(_pipe@12); <<"DD"/utf8>> -> _pipe@13 = erlang:element(4, Calendar_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_us_convention(_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("src/tempo.gleam", 3121). -spec escaped_length(bitstring(), integer()) -> {ok, integer()} | {error, nil}. escaped_length(Bytes, Length) -> case Bytes of <<"]"/utf8, _/binary>> when Length > 0 -> {ok, Length}; <<"]"/utf8, _/binary>> -> {error, nil}; <<_, Rest/binary>> -> escaped_length(Rest, Length + 1); _ -> {error, nil} end. -file("src/tempo.gleam", 3114). ?DOC( " Takes the contents of an escape sequence, everything up to the `]` that\n" " closes it. An empty escape sequence is not one.\n" ). -spec take_escaped(bitstring()) -> {ok, {binary(), bitstring()}} | {error, nil}. take_escaped(Bytes) -> gleam@result:'try'( escaped_length(Bytes, 0), fun(Length) -> gleam@result:'try'( gtempo@internal:take_string(Bytes, Length), fun(_use0) -> {Escaped, Rest} = _use0, gleam@result:map( gtempo@internal:skip(Rest, 1), fun(Rest@1) -> {Escaped, Rest@1} end ) end ) end ). -file("src/tempo.gleam", 3036). -spec do_tokenise_format(bitstring(), list(format_token())) -> list(format_token()). do_tokenise_format(Bytes, Acc) -> case Bytes of <<>> -> lists:reverse(Acc); <<"["/utf8, Rest/binary>> -> case take_escaped(Rest) of {ok, {Escaped, Rest@1}} -> do_tokenise_format(Rest@1, [{escaped, Escaped} | Acc]); {error, nil} -> do_tokenise_format(Rest, [{directive, <<"["/utf8>>} | Acc]) end; <<"YYYY"/utf8, Rest@2/binary>> -> do_tokenise_format(Rest@2, [{directive, <<"YYYY"/utf8>>} | Acc]); <<"YYY"/utf8, Rest@3/binary>> -> do_tokenise_format(Rest@3, [{directive, <<"YYY"/utf8>>} | Acc]); <<"YY"/utf8, Rest@4/binary>> -> do_tokenise_format(Rest@4, [{directive, <<"YY"/utf8>>} | Acc]); <<"Y"/utf8, Rest@5/binary>> -> do_tokenise_format(Rest@5, [{directive, <<"Y"/utf8>>} | Acc]); <<"GMT"/utf8, Rest@6/binary>> -> do_tokenise_format(Rest@6, [{directive, <<"GMT"/utf8>>} | Acc]); <<"MMMM"/utf8, Rest@7/binary>> -> do_tokenise_format(Rest@7, [{directive, <<"MMMM"/utf8>>} | Acc]); <<"MMM"/utf8, Rest@8/binary>> -> do_tokenise_format(Rest@8, [{directive, <<"MMM"/utf8>>} | Acc]); <<"MM"/utf8, Rest@9/binary>> -> do_tokenise_format(Rest@9, [{directive, <<"MM"/utf8>>} | Acc]); <<"M"/utf8, Rest@10/binary>> -> do_tokenise_format(Rest@10, [{directive, <<"M"/utf8>>} | Acc]); <<"DD"/utf8, Rest@11/binary>> -> do_tokenise_format(Rest@11, [{directive, <<"DD"/utf8>>} | Acc]); <<"D"/utf8, Rest@12/binary>> -> do_tokenise_format(Rest@12, [{directive, <<"D"/utf8>>} | Acc]); <<"dddd"/utf8, Rest@13/binary>> -> do_tokenise_format(Rest@13, [{directive, <<"dddd"/utf8>>} | Acc]); <<"ddd"/utf8, Rest@14/binary>> -> do_tokenise_format(Rest@14, [{directive, <<"ddd"/utf8>>} | Acc]); <<"dd"/utf8, Rest@15/binary>> -> do_tokenise_format(Rest@15, [{directive, <<"dd"/utf8>>} | Acc]); <<"d"/utf8, Rest@16/binary>> -> do_tokenise_format(Rest@16, [{directive, <<"d"/utf8>>} | Acc]); <<"HH"/utf8, Rest@17/binary>> -> do_tokenise_format(Rest@17, [{directive, <<"HH"/utf8>>} | Acc]); <<"H"/utf8, Rest@18/binary>> -> do_tokenise_format(Rest@18, [{directive, <<"H"/utf8>>} | Acc]); <<"hh"/utf8, Rest@19/binary>> -> do_tokenise_format(Rest@19, [{directive, <<"hh"/utf8>>} | Acc]); <<"h"/utf8, Rest@20/binary>> -> do_tokenise_format(Rest@20, [{directive, <<"h"/utf8>>} | Acc]); <<"mm"/utf8, Rest@21/binary>> -> do_tokenise_format(Rest@21, [{directive, <<"mm"/utf8>>} | Acc]); <<"m"/utf8, Rest@22/binary>> -> do_tokenise_format(Rest@22, [{directive, <<"m"/utf8>>} | Acc]); <<"ss"/utf8, Rest@23/binary>> -> do_tokenise_format(Rest@23, [{directive, <<"ss"/utf8>>} | Acc]); <<"s"/utf8, Rest@24/binary>> -> do_tokenise_format(Rest@24, [{directive, <<"s"/utf8>>} | Acc]); <<"SSSS"/utf8, Rest@25/binary>> -> do_tokenise_format(Rest@25, [{directive, <<"SSSS"/utf8>>} | Acc]); <<"SSS"/utf8, Rest@26/binary>> -> do_tokenise_format(Rest@26, [{directive, <<"SSS"/utf8>>} | Acc]); <<"ZZ"/utf8, Rest@27/binary>> -> do_tokenise_format(Rest@27, [{directive, <<"ZZ"/utf8>>} | Acc]); <<"Z"/utf8, Rest@28/binary>> -> do_tokenise_format(Rest@28, [{directive, <<"Z"/utf8>>} | Acc]); <<"zz"/utf8, Rest@29/binary>> -> do_tokenise_format(Rest@29, [{directive, <<"zz"/utf8>>} | Acc]); <<"z"/utf8, Rest@30/binary>> -> do_tokenise_format(Rest@30, [{directive, <<"z"/utf8>>} | Acc]); <<"a"/utf8, Rest@31/binary>> -> do_tokenise_format(Rest@31, [{directive, <<"a"/utf8>>} | Acc]); <<"A"/utf8, Rest@32/binary>> -> do_tokenise_format(Rest@32, [{directive, <<"A"/utf8>>} | Acc]); _ -> case gtempo@internal:take_character(Bytes) of {ok, {Character, Rest@33}} -> do_tokenise_format(Rest@33, [{directive, Character} | Acc]); {error, nil} -> lists:reverse(Acc) end end. -file("src/tempo.gleam", 3032). ?DOC(false). -spec tokenise_format(binary()) -> list(format_token()). tokenise_format(Format_str) -> do_tokenise_format(gleam_stdlib:identity(Format_str), []). -file("src/tempo.gleam", 2959). ?DOC(false). -spec get_datetime_format_str(date_time_format()) -> binary(). get_datetime_format_str(Format) -> case Format of i_s_o8601_seconds -> <<"YYYY-MM-DDTHH:mm:sszz"/utf8>>; i_s_o8601_milli -> <<"YYYY-MM-DDTHH:mm:ss.SSSzz"/utf8>>; i_s_o8601_micro -> <<"YYYY-MM-DDTHH:mm:ss.SSSSzz"/utf8>>; h_t_t_p -> <<"ddd, DD MMM YYYY HH:mm:ss GMT"/utf8>>; {date_format, i_s_o8601_date} -> <<"YYYY-MM-DD"/utf8>>; {time_format, i_s_o8601_time_seconds} -> <<"HH:mm:ss"/utf8>>; {time_format, i_s_o8601_time_milli} -> <<"HH:mm:ss.SSS"/utf8>>; {time_format, i_s_o8601_time_micro} -> <<"HH:mm:ss.SSSS"/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("src/tempo.gleam", 1003). ?DOC(false). -spec datetime_format(date_time(), date_time_format()) -> binary(). datetime_format(Datetime, Format) -> _pipe = get_datetime_format_str(Format), _pipe@1 = tokenise_format(_pipe), _pipe@5 = gleam@list:map(_pipe@1, fun(Token) -> case Token of {directive, Directive} -> _pipe@2 = Directive, _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)); {escaped, Literal} -> Literal end end), erlang:list_to_binary(_pipe@5). -file("src/tempo.gleam", 861). ?DOC(false). -spec instant_as_utc_time(instant()) -> time(). instant_as_utc_time(Instant) -> time_from_unix_micro(erlang:element(2, Instant)). -file("src/tempo.gleam", 851). ?DOC(false). -spec instant_as_utc_date(instant()) -> date(). instant_as_utc_date(Instant) -> date_from_unix_micro(erlang:element(2, Instant)). -file("src/tempo.gleam", 808). ?DOC(false). -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("src/tempo.gleam", 86). ?DOC( " Formats the current UTC system time using the provided format.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " tempo.format_utc(tempo.ISO8601Seconds)\n" " // -> \"2024-12-26T16:32:34Z\"\n" " ```\n" ). -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("src/tempo.gleam", 866). ?DOC(false). -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("src/tempo.gleam", 856). ?DOC(false). -spec instant_as_local_date(instant()) -> date(). instant_as_local_date(Instant) -> date_from_unix_micro( erlang:element(2, Instant) + erlang:element(3, Instant) ). -file("src/tempo.gleam", 817). ?DOC(false). -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("src/tempo.gleam", 98). ?DOC( " Formats the current local system time using the provided format.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " tempo.format_local(tempo.ISO8601Seconds)\n" " // -> \"2024-12-26T12:32:34-04:00\"\n" " ```\n" ). -spec format_local(date_time_format()) -> binary(). format_local(Format) -> case Format of h_t_t_p -> format_utc(h_t_t_p); _ -> _pipe = now(), _pipe@1 = instant_as_local_datetime(_pipe), datetime_format(_pipe@1, Format) end. -file("src/tempo.gleam", 2588). ?DOC(false). -spec duration_seconds_and_nanoseconds(integer(), integer()) -> gleam@time@duration:duration(). duration_seconds_and_nanoseconds(Seconds, Nanoseconds) -> _pipe = gleam@time@duration:seconds(Seconds), gleam@time@duration:add(_pipe, gleam@time@duration:nanoseconds(Nanoseconds)). -file("src/tempo.gleam", 2625). ?DOC(false). -spec duration_absolute(gleam@time@duration:duration()) -> gleam@time@duration:duration(). duration_absolute(Duration) -> {Seconds, Nanoseconds} = gleam@time@duration:to_seconds_and_nanoseconds( Duration ), case (Seconds >= 0) andalso (Nanoseconds >= 0) of true -> Duration; false -> Seconds@1 = case Seconds < 0 of true -> - Seconds; false -> Seconds end, Nanoseconds@1 = case Nanoseconds < 0 of true -> - Nanoseconds; false -> Nanoseconds end, duration_seconds_and_nanoseconds(Seconds@1, Nanoseconds@1) end. -file("src/tempo.gleam", 2577). ?DOC(false). -spec duration_microseconds(integer()) -> gleam@time@duration:duration(). duration_microseconds(Microseconds) -> gleam@time@duration:nanoseconds(Microseconds * 1000). -file("src/tempo.gleam", 901). ?DOC(false). -spec instant_difference(instant(), instant()) -> gleam@time@duration:duration(). instant_difference(A, B) -> duration_microseconds(erlang:element(4, B) - erlang:element(4, A)). -file("src/tempo.gleam", 115). ?DOC(false). -spec instant_since(instant()) -> gleam@time@duration:duration(). instant_since(Start) -> _pipe = now(), _pipe@1 = instant_difference(Start, _pipe), duration_absolute(_pipe@1). -file("src/tempo.gleam", 130). ?DOC(false). -spec instant_since_formatted(instant()) -> binary(). instant_since_formatted(Start) -> _pipe = instant_since(Start), _pipe@1 = duration_get_microseconds(_pipe), gtempo@internal:format(_pipe@1). -file("src/tempo.gleam", 1420). ?DOC(false). -spec offset_to_duration(offset()) -> gleam@time@duration:duration(). offset_to_duration(Offset) -> _pipe = erlang:element(2, Offset) * 60000000, duration_microseconds(_pipe). -file("src/tempo.gleam", 2452). ?DOC(false). -spec time_to_microseconds(time()) -> integer(). time_to_microseconds(Time) -> case time_normalise(Time) of {time_of_day, Microseconds} -> Microseconds; last_instant_of_day -> 86400000000; {end_of_day_leap_second, Microsecond} -> 86400000000 + Microsecond end. -file("src/tempo.gleam", 2562). ?DOC(false). -spec time_subtract(time(), gleam@time@duration:duration()) -> time(). time_subtract(A, B) -> case duration_get_microseconds(B) =:= 0 of true -> A; false -> _pipe = time_to_microseconds(A) - duration_get_microseconds(B), _pipe@1 = time_from_microseconds(_pipe), time_normalise(_pipe@1) end. -file("src/tempo.gleam", 1813). ?DOC(false). -spec date_subtract(date(), integer()) -> date(). date_subtract(Date, Days) -> {date, erlang:element(2, Date) - Days}. -file("src/tempo.gleam", 2670). ?DOC(false). -spec duration_as_microseconds(gleam@time@duration:duration()) -> integer(). duration_as_microseconds(Duration) -> duration_get_microseconds(Duration). -file("src/tempo.gleam", 2646). ?DOC(false). -spec duration_inverse(gleam@time@duration:duration()) -> gleam@time@duration:duration(). duration_inverse(Dur) -> gleam@time@duration:difference(Dur, gleam@time@duration:seconds(0)). -file("src/tempo.gleam", 2617). ?DOC(false). -spec duration_decrease( gleam@time@duration:duration(), gleam@time@duration:duration() ) -> gleam@time@duration:duration(). duration_decrease(A, B) -> gleam@time@duration:add(A, duration_inverse(B)). -file("src/tempo.gleam", 2503). ?DOC(false). -spec time_to_duration(time()) -> gleam@time@duration:duration(). time_to_duration(Time) -> _pipe = time_to_microseconds(Time), duration_microseconds(_pipe). -file("src/tempo.gleam", 2604). ?DOC(false). -spec duration_days(integer()) -> gleam@time@duration:duration(). duration_days(Days) -> _pipe = Days, _pipe@1 = gtempo@internal:imprecise_days(_pipe), duration_microseconds(_pipe@1). -file("src/tempo.gleam", 2665). ?DOC(false). -spec duration_as_days(gleam@time@duration:duration()) -> integer(). duration_as_days(Duration) -> _pipe = duration_get_microseconds(Duration), gtempo@internal:as_days_imprecise(_pipe). -file("src/tempo.gleam", 2538). ?DOC(false). -spec time_add(time(), gleam@time@duration:duration()) -> time(). time_add(A, B) -> B_microseconds = duration_get_microseconds(B), case B_microseconds =:= 0 of true -> A; false -> case A of {end_of_day_leap_second, Microsecond} when (B_microseconds + Microsecond) < 1000000 -> {end_of_day_leap_second, Microsecond + B_microseconds}; {end_of_day_leap_second, _} -> _pipe = time_to_microseconds(A) + (B_microseconds - 1000000), _pipe@1 = time_from_microseconds(_pipe), time_normalise(_pipe@1); _ -> _pipe@2 = time_to_microseconds(A) + B_microseconds, _pipe@3 = time_from_microseconds(_pipe@2), time_normalise(_pipe@3) end end. -file("src/tempo.gleam", 1808). ?DOC(false). -spec date_add(date(), integer()) -> date(). date_add(Date, Days) -> {date, erlang:element(2, Date) + Days}. -file("src/tempo.gleam", 2609). ?DOC(false). -spec duration_increase( gleam@time@duration:duration(), gleam@time@duration:duration() ) -> gleam@time@duration:duration(). duration_increase(A, B) -> gleam@time@duration:add(A, B). -file("src/tempo.gleam", 2659). ?DOC(false). -spec duration_is_positive(gleam@time@duration:duration()) -> boolean(). duration_is_positive(Dur) -> {Seconds, Nanoseconds} = gleam@time@duration:to_seconds_and_nanoseconds(Dur), (Seconds >= 0) andalso (Nanoseconds >= 0). -file("src/tempo.gleam", 1233). ?DOC(false). -spec naive_datetime_add(naive_date_time(), gleam@time@duration:duration()) -> naive_date_time(). naive_datetime_add(Datetime, Duration_to_add) -> gleam@bool:lazy_guard( not duration_is_positive(Duration_to_add), 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_microseconds( 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("src/tempo.gleam", 1278). ?DOC(false). -spec naive_datetime_subtract(naive_date_time(), gleam@time@duration:duration()) -> naive_date_time(). naive_datetime_subtract(Datetime, Duration_to_subtract) -> gleam@bool:lazy_guard( not duration_is_positive(Duration_to_subtract), 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_microseconds( 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("src/tempo.gleam", 1078). ?DOC(false). -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("src/tempo.gleam", 1066). ?DOC(false). -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_subtract( _pipe@1, offset_to_duration(erlang:element(4, Datetime)) ) end, {naive_date_time, erlang:element(2, Applied), erlang:element(3, Applied)}. -file("src/tempo.gleam", 2508). ?DOC(false). -spec time_compare(time(), time()) -> gleam@order:order(). time_compare(A, B) -> gleam@int:compare(time_to_microseconds(A), time_to_microseconds(B)). -file("src/tempo.gleam", 1823). ?DOC(false). -spec date_compare(date(), date()) -> gleam@order:order(). date_compare(A, B) -> gleam@int:compare(erlang:element(2, A), erlang:element(2, B)). -file("src/tempo.gleam", 1189). ?DOC(false). -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("src/tempo.gleam", 1024). ?DOC(false). -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("src/tempo.gleam", 143). ?DOC( " Compares the current system time to the provided datetime value.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " tempo.compare(datetime.literal(\"2024-12-26T00:00:00Z\"))\n" " // -> order.Lt\n" ). -spec compare(date_time()) -> gleam@order:order(). compare(Datetime) -> datetime_compare( begin _pipe = now(), instant_as_utc_datetime(_pipe) end, Datetime ). -file("src/tempo.gleam", 1030). ?DOC(false). -spec datetime_is_earlier(date_time(), date_time()) -> boolean(). datetime_is_earlier(A, B) -> datetime_compare(A, B) =:= lt. -file("src/tempo.gleam", 155). ?DOC( " Checks if the current system time is earlier than the provided datetime.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " tempo.is_earlier(than: datetime.literal(\"2024-12-26T00:00:00Z\"))\n" " // -> False\n" " ```\n" ). -spec is_earlier(date_time()) -> boolean(). is_earlier(Datetime) -> datetime_is_earlier( begin _pipe = now(), instant_as_utc_datetime(_pipe) end, Datetime ). -file("src/tempo.gleam", 1035). ?DOC(false). -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("src/tempo.gleam", 168). ?DOC( " Checks if the current system time is earlier or equal to the provided\n" " datetime.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " tempo.is_earlier_or_equal(to: datetime.literal(\"2024-12-26T00:00:00Z\"))\n" " // -> True\n" " ```\n" ). -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("src/tempo.gleam", 1040). ?DOC(false). -spec datetime_is_equal(date_time(), date_time()) -> boolean(). datetime_is_equal(A, B) -> datetime_compare(A, B) =:= eq. -file("src/tempo.gleam", 179). ?DOC( " Checks if the current system time is equal to the provided datetime.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " tempo.is_equal(to: datetime.literal(\"2024-12-26T00:00:00Z\"))\n" " // -> False\n" ). -spec is_equal(date_time()) -> boolean(). is_equal(Datetime) -> datetime_is_equal( begin _pipe = now(), instant_as_utc_datetime(_pipe) end, Datetime ). -file("src/tempo.gleam", 1050). ?DOC(false). -spec datetime_is_later(date_time(), date_time()) -> boolean(). datetime_is_later(A, B) -> datetime_compare(A, B) =:= gt. -file("src/tempo.gleam", 191). ?DOC( " Checks if the current system time is later than the provided datetime.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " tempo.is_later(than: datetime.literal(\"2024-12-26T00:00:00Z\"))\n" " // -> True\n" " ```\n" ). -spec is_later(date_time()) -> boolean(). is_later(Datetime) -> datetime_is_later( begin _pipe = now(), instant_as_utc_datetime(_pipe) end, Datetime ). -file("src/tempo.gleam", 1045). ?DOC(false). -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("src/tempo.gleam", 204). ?DOC( " Checks if the current system time is later or equal to the provided\n" " datetime.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " tempo.is_later_or_equal(to: datetime.literal(\"2024-12-26T00:00:00Z\"))\n" " // -> True\n" " ```\n" ). -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("src/tempo.gleam", 220). ?DOC(false). -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("src/tempo.gleam", 236). ?DOC(false). -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("src/tempo.gleam", 1828). ?DOC(false). -spec date_is_earlier(date(), date()) -> boolean(). date_is_earlier(A, B) -> date_compare(A, B) =:= lt. -file("src/tempo.gleam", 249). ?DOC(false). -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("src/tempo.gleam", 262). ?DOC(false). -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("src/tempo.gleam", 1833). ?DOC(false). -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("src/tempo.gleam", 275). ?DOC(false). -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("src/tempo.gleam", 288). ?DOC(false). -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("src/tempo.gleam", 1838). ?DOC(false). -spec date_is_equal(date(), date()) -> boolean(). date_is_equal(A, B) -> date_compare(A, B) =:= eq. -file("src/tempo.gleam", 301). ?DOC(false). -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("src/tempo.gleam", 314). ?DOC(false). -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("src/tempo.gleam", 1843). ?DOC(false). -spec date_is_later(date(), date()) -> boolean(). date_is_later(A, B) -> date_compare(A, B) =:= gt. -file("src/tempo.gleam", 327). ?DOC(false). -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("src/tempo.gleam", 340). ?DOC(false). -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("src/tempo.gleam", 1848). ?DOC(false). -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("src/tempo.gleam", 353). ?DOC(false). -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("src/tempo.gleam", 366). ?DOC(false). -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("src/tempo.gleam", 379). ?DOC(false). -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("src/tempo.gleam", 392). ?DOC(false). -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("src/tempo.gleam", 2513). ?DOC(false). -spec time_is_earlier(time(), time()) -> boolean(). time_is_earlier(A, B) -> time_compare(A, B) =:= lt. -file("src/tempo.gleam", 405). ?DOC(false). -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("src/tempo.gleam", 418). ?DOC(false). -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("src/tempo.gleam", 2518). ?DOC(false). -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("src/tempo.gleam", 431). ?DOC(false). -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("src/tempo.gleam", 444). ?DOC(false). -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("src/tempo.gleam", 2523). ?DOC(false). -spec time_is_equal(time(), time()) -> boolean(). time_is_equal(A, B) -> time_compare(A, B) =:= eq. -file("src/tempo.gleam", 457). ?DOC(false). -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("src/tempo.gleam", 470). ?DOC(false). -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("src/tempo.gleam", 2528). ?DOC(false). -spec time_is_later(time(), time()) -> boolean(). time_is_later(A, B) -> time_compare(A, B) =:= gt. -file("src/tempo.gleam", 483). ?DOC(false). -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("src/tempo.gleam", 496). ?DOC(false). -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("src/tempo.gleam", 2533). ?DOC(false). -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("src/tempo.gleam", 509). ?DOC(false). -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("src/tempo.gleam", 522). ?DOC(false). -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("src/tempo.gleam", 2447). ?DOC(false). -spec time_difference(time(), time()) -> gleam@time@duration:duration(). time_difference(A, B) -> _pipe = time_to_microseconds(B) - time_to_microseconds(A), duration_microseconds(_pipe). -file("src/tempo.gleam", 1818). ?DOC(false). -spec date_days_apart(date(), date()) -> integer(). date_days_apart(Start_date, End_date) -> erlang:element(2, End_date) - erlang:element(2, Start_date). -file("src/tempo.gleam", 1223). ?DOC(false). -spec naive_datetime_difference(naive_date_time(), naive_date_time()) -> gleam@time@duration: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("src/tempo.gleam", 1055). ?DOC(false). -spec datetime_difference(date_time(), date_time()) -> gleam@time@duration:duration(). datetime_difference(A, B) -> naive_datetime_difference( datetime_apply_offset(A), datetime_apply_offset(B) ). -file("src/tempo.gleam", 536). ?DOC( " Gets the difference between the current system datetime and the provided\n" " datetime.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " tempo.difference(from: datetime.literal(\"2024-10-26T00:00:00Z\"))\n" " |> duration.format\n" " // -> \"54 days, 13 hours, and 46 minutes\"\n" " ```\n" ). -spec difference(date_time()) -> gleam@time@duration:duration(). difference(Start) -> _pipe = now(), _pipe@1 = instant_as_utc_datetime(_pipe), datetime_difference(Start, _pipe@1). -file("src/tempo.gleam", 2651). ?DOC(false). -spec duration_clamp_to_zero(gleam@time@duration:duration()) -> gleam@time@duration:duration(). duration_clamp_to_zero(Dur) -> case duration_is_positive(Dur) of true -> Dur; false -> gleam@time@duration:seconds(0) end. -file("src/tempo.gleam", 557). ?DOC( " Gets the time since the provided datetime relative to the current system\n" " time. The same as `tempo.difference`, but a duration of 0 will be\n" " returned instead if the datetime is in the future.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " tempo.since(datetime.literal(\"2024-10-26T00:00:00Z\"))\n" " |> duration.format\n" " // -> \"54 days, 13 hours, and 46 minutes\"\n" " ```\n" "\n" " ```gleam\n" " tempo.since(datetime.literal(\"9099-12-26T00:00:00Z\"))\n" " |> duration.format\n" " // -> \"none\"\n" " ```\n" ). -spec since(date_time()) -> gleam@time@duration:duration(). since(Start) -> _pipe = difference(Start), duration_clamp_to_zero(_pipe). -file("src/tempo.gleam", 577). ?DOC( " Gets the time until the provided datetime relative to the current system\n" " time. A duration of 0 will be returned if the datetime is in the past.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " tempo.until(datetime.literal(\"2024-10-26T00:00:00Z\"))\n" " |> duration.format\n" " // -> \"none\"\n" " ```\n" "\n" " ```gleam\n" " tempo.until(datetime.literal(\"2025-02-26T00:00:00Z\"))\n" " |> duration.format\n" " // -> \"54 days, 13 hours, and 46 minutes\"\n" " ```\n" ). -spec until(date_time()) -> gleam@time@duration:duration(). until(End) -> _pipe = now(), _pipe@1 = instant_as_utc_datetime(_pipe), _pipe@2 = datetime_difference(_pipe@1, End), duration_clamp_to_zero(_pipe@2). -file("src/tempo.gleam", 593). ?DOC(false). -spec utc_time_difference_from(time()) -> gleam@time@duration:duration(). utc_time_difference_from(Start) -> _pipe = now(), _pipe@1 = instant_as_utc_time(_pipe), time_difference(Start, _pipe@1). -file("src/tempo.gleam", 608). ?DOC(false). -spec local_time_difference_from(time()) -> gleam@time@duration:duration(). local_time_difference_from(Start) -> _pipe = now(), _pipe@1 = instant_as_utc_time(_pipe), time_difference(Start, _pipe@1). -file("src/tempo.gleam", 623). ?DOC(false). -spec utc_time_since(time()) -> gleam@time@duration:duration(). utc_time_since(Start) -> _pipe = utc_time_difference_from(Start), duration_clamp_to_zero(_pipe). -file("src/tempo.gleam", 639). ?DOC(false). -spec local_time_since(time()) -> gleam@time@duration:duration(). local_time_since(Start) -> _pipe = local_time_difference_from(Start), duration_clamp_to_zero(_pipe). -file("src/tempo.gleam", 655). ?DOC(false). -spec utc_time_until(time()) -> gleam@time@duration:duration(). utc_time_until(End) -> _pipe = now(), _pipe@1 = instant_as_utc_time(_pipe), _pipe@2 = time_difference(_pipe@1, End), duration_clamp_to_zero(_pipe@2). -file("src/tempo.gleam", 673). ?DOC(false). -spec local_time_until(time()) -> gleam@time@duration:duration(). local_time_until(End) -> _pipe = now(), _pipe@1 = instant_as_local_time(_pipe), _pipe@2 = time_difference(_pipe@1, End), duration_clamp_to_zero(_pipe@2). -file("src/tempo.gleam", 689). ?DOC(false). -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("src/tempo.gleam", 702). ?DOC(false). -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("src/tempo.gleam", 716). ?DOC(false). -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("src/tempo.gleam", 733). ?DOC(false). -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("src/tempo.gleam", 750). ?DOC(false). -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("src/tempo.gleam", 767). ?DOC(false). -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("src/tempo.gleam", 4065). ?DOC(false). -spec sleep_ffi(integer()) -> nil. sleep_ffi(Milliseconds) -> tempo_ffi:sleep(Milliseconds). -file("src/tempo.gleam", 776). ?DOC( " Sleeps the current process for the provided duration. If the duration is\n" " less than a millisecond, the process will not sleep at all.\n" ). -spec sleep(gleam@time@duration:duration()) -> nil. sleep(Duration) -> Sleep_ms = case duration_get_microseconds(Duration) div 1000 of Ms when Ms > 0 -> Ms; _ -> 0 end, tempo_ffi:sleep(Sleep_ms). -file("src/tempo.gleam", 803). ?DOC(false). -spec instant_get_unique(instant()) -> integer(). instant_get_unique(Instant) -> erlang:element(5, Instant). -file("src/tempo.gleam", 826). ?DOC(false). -spec instant_as_unix_seconds(instant()) -> integer(). instant_as_unix_seconds(Instant) -> erlang:element(2, Instant) div 1000000. -file("src/tempo.gleam", 831). ?DOC(false). -spec instant_as_unix_milli(instant()) -> integer(). instant_as_unix_milli(Instant) -> erlang:element(2, Instant) div 1000. -file("src/tempo.gleam", 836). ?DOC(false). -spec instant_as_unix_micro(instant()) -> integer(). instant_as_unix_micro(Instant) -> erlang:element(2, Instant). -file("src/tempo.gleam", 2461). ?DOC(false). -spec time_to_parts(time()) -> {integer(), integer(), integer(), integer()}. time_to_parts(Time) -> case time_normalise(Time) of {time_of_day, Microseconds} -> Hour = case 3600000000 of 0 -> 0; Gleam@denominator -> Microseconds div Gleam@denominator end, Minute = case 60000000 of 0 -> 0; Gleam@denominator@1 -> (Microseconds - (Hour * 3600000000)) div Gleam@denominator@1 end, Second = case 1000000 of 0 -> 0; Gleam@denominator@2 -> ((Microseconds - (Hour * 3600000000)) - (Minute * 60000000)) div Gleam@denominator@2 end, Microsecond = ((Microseconds - (Hour * 3600000000)) - (Minute * 60000000)) - (Second * 1000000), {Hour, Minute, Second, Microsecond}; last_instant_of_day -> {24, 0, 0, 0}; {end_of_day_leap_second, Microsecond@1} -> {23, 59, 60, Microsecond@1} end. -file("src/tempo.gleam", 2347). ?DOC(false). -spec time_to_string(time()) -> binary(). time_to_string(Time) -> {Hour, Minute, Second, Microsecond} = time_to_parts(Time), _pipe@6 = gleam_stdlib:identity( [begin _pipe = Hour, _pipe@1 = erlang:integer_to_binary(_pipe), gleam@string:pad_start(_pipe@1, 2, <<"0"/utf8>>) end, <<":"/utf8>>, begin _pipe@2 = Minute, _pipe@3 = erlang:integer_to_binary(_pipe@2), gleam@string:pad_start(_pipe@3, 2, <<"0"/utf8>>) end, <<":"/utf8>>, begin _pipe@4 = Second, _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 = Microsecond, _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("src/tempo.gleam", 1549). ?DOC(false). -spec date_to_string(date()) -> binary(). date_to_string(Date) -> Calendar_date = date_to_calendar_date(Date), _pipe@3 = gleam_stdlib:identity( [erlang:integer_to_binary(erlang:element(2, Calendar_date)), <<"-"/utf8>>, begin _pipe = month_to_int(erlang:element(3, Calendar_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, Calendar_date) ), gleam@string:pad_start(_pipe@2, 2, <<"0"/utf8>>) end] ), unicode:characters_to_binary(_pipe@3). -file("src/tempo.gleam", 1180). ?DOC(false). -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("src/tempo.gleam", 986). ?DOC(false). -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("src/tempo.gleam", 841). ?DOC(false). -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("src/tempo.gleam", 846). ?DOC(false). -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("src/tempo.gleam", 871). ?DOC(false). -spec instant_compare(instant(), instant()) -> gleam@order:order(). instant_compare(A, B) -> gleam@int:compare(erlang:element(5, A), erlang:element(5, B)). -file("src/tempo.gleam", 876). ?DOC(false). -spec instant_is_earlier(instant(), instant()) -> boolean(). instant_is_earlier(A, B) -> instant_compare(A, B) =:= lt. -file("src/tempo.gleam", 881). ?DOC(false). -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("src/tempo.gleam", 886). ?DOC(false). -spec instant_is_equal(instant(), instant()) -> boolean(). instant_is_equal(A, B) -> instant_compare(A, B) =:= eq. -file("src/tempo.gleam", 891). ?DOC(false). -spec instant_is_later(instant(), instant()) -> boolean(). instant_is_later(A, B) -> instant_compare(A, B) =:= gt. -file("src/tempo.gleam", 896). ?DOC(false). -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("src/tempo.gleam", 934). ?DOC(false). -spec datetime(date(), time(), offset()) -> date_time(). datetime(Date, Time, Offset) -> {date_time, Date, Time, Offset}. -file("src/tempo.gleam", 939). ?DOC(false). -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("src/tempo.gleam", 944). ?DOC(false). -spec datetime_get_offset(date_time()) -> offset(). datetime_get_offset(Datetime) -> erlang:element(4, Datetime). -file("src/tempo.gleam", 1172). ?DOC(false). -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("src/tempo.gleam", 949). ?DOC(false). -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("src/tempo.gleam", 1083). ?DOC(false). -spec datetime_add(date_time(), gleam@time@duration: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("src/tempo.gleam", 956). ?DOC(false). -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_add(_pipe@1, offset_to_duration(Offset)), _pipe@3 = datetime_drop_offset(_pipe@2), naive_datetime_set_offset(_pipe@3, Offset). -file("src/tempo.gleam", 965). ?DOC(false). -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("src/tempo.gleam", 978). ?DOC(false). -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("src/tempo.gleam", 1793). ?DOC(false). -spec date_to_unix_micro(date()) -> integer(). date_to_unix_micro(Date) -> erlang:element(2, Date) * 86400000000. -file("src/tempo.gleam", 996). ?DOC(false). -spec datetime_to_unix_micro(date_time()) -> integer(). datetime_to_unix_micro(Datetime) -> Utc_dt = begin _pipe = Datetime, datetime_apply_offset(_pipe) end, date_to_unix_micro(erlang:element(2, Utc_dt)) + (time_to_microseconds( erlang:element(3, Utc_dt) )). -file("src/tempo.gleam", 1115). ?DOC(false). -spec datetime_subtract(date_time(), gleam@time@duration: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("src/tempo.gleam", 1157). ?DOC(false). -spec naive_datetime(date(), time()) -> naive_date_time(). naive_datetime(Date, Time) -> {naive_date_time, Date, Time}. -file("src/tempo.gleam", 1162). ?DOC(false). -spec naive_datetime_get_date(naive_date_time()) -> date(). naive_datetime_get_date(Naive_datetime) -> erlang:element(2, Naive_datetime). -file("src/tempo.gleam", 1167). ?DOC(false). -spec naive_datetime_get_time(naive_date_time()) -> time(). naive_datetime_get_time(Naive_datetime) -> erlang:element(3, Naive_datetime). -file("src/tempo.gleam", 1197). ?DOC(false). -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("src/tempo.gleam", 1205). ?DOC(false). -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("src/tempo.gleam", 1214). ?DOC(false). -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("src/tempo.gleam", 1338). ?DOC(false). -spec offset(integer()) -> offset(). offset(Minutes) -> {offset, Minutes}. -file("src/tempo.gleam", 1411). ?DOC(false). -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("src/tempo.gleam", 2594). ?DOC(false). -spec duration_as_mintues(gleam@time@duration:duration()) -> integer(). duration_as_mintues(Duration) -> _pipe = duration_get_microseconds(Duration), gtempo@internal:as_minutes(_pipe). -file("src/tempo.gleam", 1351). ?DOC(false). -spec new_offset(gleam@time@duration:duration()) -> {ok, offset()} | {error, nil}. new_offset(Duration) -> _pipe = duration_as_mintues(Duration), _pipe@1 = {offset, _pipe}, validate_offset(_pipe@1). -file("src/tempo.gleam", 1368). -spec parse_offset_string(bitstring()) -> {ok, offset()} | {error, nil}. parse_offset_string(Input) -> gleam@result:'try'( gtempo@internal:take_offset_minutes(Input), fun(_use0) -> {Minutes, Input@1} = _use0, gleam@result:map( gtempo@internal:accept_empty(Input@1), fun(_use0@1) -> nil = _use0@1, {offset, Minutes} end ) end ). -file("src/tempo.gleam", 1356). ?DOC(false). -spec offset_from_string(binary()) -> {ok, offset()} | {error, tempo@error:offset_parse_error()}. offset_from_string(Offset_str) -> gleam@result:'try'( begin _pipe = parse_offset_string(gleam_stdlib:identity(Offset_str)), gleam@result:replace_error( _pipe, {offset_invalid_format, Offset_str} ) end, fun(Offset) -> _pipe@1 = validate_offset(Offset), gleam@result:replace_error( _pipe@1, {offset_out_of_bounds, Offset_str} ) end ). -file("src/tempo.gleam", 1463). ?DOC(false). -spec date(integer()) -> date(). date(Unix_days) -> {date, Unix_days}. -file("src/tempo.gleam", 1468). ?DOC(false). -spec date_get_unix_days(date()) -> integer(). date_get_unix_days(Date) -> erlang:element(2, Date). -file("src/tempo.gleam", 1803). -spec date_from_rata_die(integer()) -> date(). date_from_rata_die(Rata_die) -> {date, Rata_die - 719163}. -file("src/tempo.gleam", 1756). ?DOC(false). -spec date_calendar_to_unix_days(gleam@time@calendar:date()) -> date(). date_calendar_to_unix_days(Date) -> Year_days = date_days_before_year(erlang:element(2, Date)), Leap_days = case is_leap_year(erlang:element(2, Date)) of true -> 1; false -> 0 end, Month_days = case erlang:element(3, Date) of january -> 0; february -> 31; march -> 59 + Leap_days; april -> 90 + Leap_days; may -> 120 + Leap_days; june -> 151 + Leap_days; july -> 181 + Leap_days; august -> 212 + Leap_days; september -> 243 + Leap_days; october -> 273 + Leap_days; november -> 304 + Leap_days; december -> 334 + Leap_days end, _pipe = (Year_days + Month_days) + erlang:element(4, Date), date_from_rata_die(_pipe). -file("src/tempo.gleam", 1478). ?DOC(false). -spec date_from_calendar_date(gleam@time@calendar:date()) -> date(). date_from_calendar_date(Calendar_date) -> date_calendar_to_unix_days(Calendar_date). -file("src/tempo.gleam", 1483). ?DOC(false). -spec date_get_month_year(date()) -> month_year(). date_get_month_year(Date) -> Calendar_date = date_to_calendar_date(Date), {month_year, erlang:element(3, Calendar_date), erlang:element(2, Calendar_date)}. -file("src/tempo.gleam", 1515). ?DOC(false). -spec date_get_month(date()) -> gleam@time@calendar:month(). date_get_month(Date) -> erlang:element(3, date_to_calendar_date(Date)). -file("src/tempo.gleam", 1520). ?DOC(false). -spec date_get_day(date()) -> integer(). date_get_day(Date) -> erlang:element(4, date_to_calendar_date(Date)). -file("src/tempo.gleam", 1649). ?DOC(false). -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_from_calendar_date( {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("src/tempo.gleam", 1525). ?DOC(false). -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("src/tempo.gleam", 1534). ?DOC(false). -spec date_from_unix_seconds(integer()) -> date(). date_from_unix_seconds(Unix_ts) -> {date, Unix_ts div 86400}. -file("src/tempo.gleam", 1539). ?DOC(false). -spec date_from_unix_milli(integer()) -> date(). date_from_unix_milli(Unix_milli) -> {date, Unix_milli div 86400000}. -file("src/tempo.gleam", 1751). ?DOC(false). -spec date_calendar_from_unix_seconds(integer()) -> gleam@time@calendar:date(). date_calendar_from_unix_seconds(Unix_ts) -> date_calendar_from_unix_days(Unix_ts div 86400). -file("src/tempo.gleam", 1783). ?DOC(false). -spec date_to_unix_seconds(date()) -> integer(). date_to_unix_seconds(Date) -> erlang:element(2, Date) * 86400. -file("src/tempo.gleam", 1788). ?DOC(false). -spec date_to_unix_milli(date()) -> integer(). date_to_unix_milli(Date) -> erlang:element(2, Date) * 86400000. -file("src/tempo.gleam", 1886). ?DOC(false). -spec month_from_short_string(binary()) -> {ok, gleam@time@calendar:month()} | {error, nil}. month_from_short_string(Month) -> case Month of <<"Jan"/utf8>> -> {ok, january}; <<"Feb"/utf8>> -> {ok, february}; <<"Mar"/utf8>> -> {ok, march}; <<"Apr"/utf8>> -> {ok, april}; <<"May"/utf8>> -> {ok, may}; <<"Jun"/utf8>> -> {ok, june}; <<"Jul"/utf8>> -> {ok, july}; <<"Aug"/utf8>> -> {ok, august}; <<"Sep"/utf8>> -> {ok, september}; <<"Oct"/utf8>> -> {ok, october}; <<"Nov"/utf8>> -> {ok, november}; <<"Dec"/utf8>> -> {ok, december}; _ -> {error, nil} end. -file("src/tempo.gleam", 1905). ?DOC(false). -spec month_from_long_string(binary()) -> {ok, gleam@time@calendar:month()} | {error, nil}. month_from_long_string(Month) -> case Month of <<"January"/utf8>> -> {ok, january}; <<"February"/utf8>> -> {ok, february}; <<"March"/utf8>> -> {ok, march}; <<"April"/utf8>> -> {ok, april}; <<"May"/utf8>> -> {ok, may}; <<"June"/utf8>> -> {ok, june}; <<"July"/utf8>> -> {ok, july}; <<"August"/utf8>> -> {ok, august}; <<"September"/utf8>> -> {ok, september}; <<"October"/utf8>> -> {ok, october}; <<"November"/utf8>> -> {ok, november}; <<"December"/utf8>> -> {ok, december}; _ -> {error, nil} end. -file("src/tempo.gleam", 1992). ?DOC(false). -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("src/tempo.gleam", 1997). ?DOC(false). -spec month_year_prior(month_year()) -> month_year(). month_year_prior(Month_year) -> case erlang:element(2, Month_year) of january -> {month_year, december, erlang:element(3, Month_year) - 1}; february -> {month_year, january, erlang:element(3, Month_year)}; march -> {month_year, february, erlang:element(3, Month_year)}; april -> {month_year, march, erlang:element(3, Month_year)}; may -> {month_year, april, erlang:element(3, Month_year)}; june -> {month_year, may, erlang:element(3, Month_year)}; july -> {month_year, june, erlang:element(3, Month_year)}; august -> {month_year, july, erlang:element(3, Month_year)}; september -> {month_year, august, erlang:element(3, Month_year)}; october -> {month_year, september, erlang:element(3, Month_year)}; november -> {month_year, october, erlang:element(3, Month_year)}; december -> {month_year, november, erlang:element(3, Month_year)} end. -file("src/tempo.gleam", 2015). ?DOC(false). -spec month_year_next(month_year()) -> month_year(). month_year_next(Month_year) -> case erlang:element(2, Month_year) of january -> {month_year, february, erlang:element(3, Month_year)}; february -> {month_year, march, erlang:element(3, Month_year)}; march -> {month_year, april, erlang:element(3, Month_year)}; april -> {month_year, may, erlang:element(3, Month_year)}; may -> {month_year, june, erlang:element(3, Month_year)}; june -> {month_year, july, erlang:element(3, Month_year)}; july -> {month_year, august, erlang:element(3, Month_year)}; august -> {month_year, september, erlang:element(3, Month_year)}; september -> {month_year, october, erlang:element(3, Month_year)}; october -> {month_year, november, erlang:element(3, Month_year)}; november -> {month_year, december, erlang:element(3, Month_year)}; december -> {month_year, january, erlang:element(3, Month_year) + 1} end. -file("src/tempo.gleam", 2075). ?DOC(false). -spec year_days(integer()) -> integer(). year_days(Year) -> case is_leap_year(Year) of true -> 366; false -> 365 end. -file("src/tempo.gleam", 2107). ?DOC(false). -spec time(integer(), integer(), integer(), integer()) -> time(). time(Hour, Minute, Second, Microsecond) -> case (((Hour =:= 24) andalso (Minute =:= 0)) andalso (Second =:= 0)) andalso (Microsecond =:= 0) of true -> last_instant_of_day; false -> case ((Hour =:= 23) andalso (Minute =:= 59)) andalso (Second =:= 60) of true -> {end_of_day_leap_second, Microsecond}; false -> {time_of_day, (((Hour * 3600000000) + (Minute * 60000000)) + (Second * 1000000)) + Microsecond} end end. -file("src/tempo.gleam", 2323). -spec time_parts_to_string(integer(), integer(), integer(), integer()) -> binary(). time_parts_to_string(Hour, Minute, Second, Microsecond) -> _pipe@6 = gleam_stdlib:identity( [begin _pipe = Hour, _pipe@1 = erlang:integer_to_binary(_pipe), gleam@string:pad_start(_pipe@1, 2, <<"0"/utf8>>) end, <<":"/utf8>>, begin _pipe@2 = Minute, _pipe@3 = erlang:integer_to_binary(_pipe@2), gleam@string:pad_start(_pipe@3, 2, <<"0"/utf8>>) end, <<":"/utf8>>, begin _pipe@4 = Second, _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 = Microsecond, _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("src/tempo.gleam", 2255). ?DOC(false). -spec validate_time(integer(), integer(), integer(), integer()) -> {ok, time()} | {error, tempo@error:time_out_of_bounds_error()}. validate_time(Hour, Minute, Second, Microsecond) -> case (((((((Hour >= 0) andalso (Hour =< 23)) andalso (Minute >= 0)) andalso (Minute =< 59)) andalso (Second >= 0)) andalso (Second =< 59)) orelse ((((Hour =:= 24) andalso (Minute =:= 0)) andalso (Second =:= 0)) andalso (Microsecond =:= 0))) orelse (((Hour =:= 23) andalso (Minute =:= 59)) andalso (Second =:= 60)) of true -> case Microsecond =< 999999 of true -> {ok, time(Hour, Minute, Second, Microsecond)}; false -> {error, {time_micro_second_out_of_bounds, time_parts_to_string( Hour, Minute, Second, Microsecond )}} end; false -> case {Hour, Minute, Second} of {_, _, S} when (S > 59) orelse (S < 0) -> {error, {time_second_out_of_bounds, time_parts_to_string( Hour, Minute, Second, Microsecond )}}; {_, M, _} when (M > 59) orelse (M < 0) -> {error, {time_minute_out_of_bounds, time_parts_to_string( Hour, Minute, Second, Microsecond )}}; {_, _, _} -> {error, {time_hour_out_of_bounds, time_parts_to_string( Hour, Minute, Second, Microsecond )}} end end. -file("src/tempo.gleam", 2226). ?DOC(false). -spec new_time(integer(), integer(), integer()) -> {ok, time()} | {error, tempo@error:time_out_of_bounds_error()}. new_time(Hour, Minute, Second) -> validate_time(Hour, Minute, Second, 0). -file("src/tempo.gleam", 2235). ?DOC(false). -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) -> validate_time(Hour, Minute, Second, Millisecond * 1000). -file("src/tempo.gleam", 2245). ?DOC(false). -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) -> validate_time(Hour, Minute, Second, Microsecond). -file("src/tempo.gleam", 2372). ?DOC(false). -spec time_to_calendar_time_of_day(time()) -> gleam@time@calendar:time_of_day(). time_to_calendar_time_of_day(Time) -> {time_of_day, time_get_hour(Time), time_get_minute(Time), time_get_second(Time), time_get_micro(Time) * 1000}. -file("src/tempo.gleam", 2437). ?DOC(false). -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("src/tempo.gleam", 2599). ?DOC(false). -spec duration_minutes(integer()) -> gleam@time@duration:duration(). duration_minutes(Minutes) -> _pipe = Minutes, _pipe@1 = gtempo@internal:minutes(_pipe), duration_microseconds(_pipe@1). -file("src/tempo.gleam", 2689). ?DOC(false). -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("src/tempo.gleam", 2699). ?DOC(false). -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("src/tempo.gleam", 2711). ?DOC(false). -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("src/tempo.gleam", 2731). ?DOC(false). -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_of_day, 0}, last_instant_of_day}; {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("src/tempo.gleam", 2721). ?DOC(false). -spec period_as_duration(period()) -> gleam@time@duration: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("src/tempo.gleam", 2764). ?DOC(false). -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("src/tempo.gleam", 2747). ?DOC(false). -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. -file("src/tempo.gleam", 2788). -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("src/tempo.gleam", 2778). ?DOC(false). -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("src/tempo.gleam", 2824). -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_from_calendar_date( {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("src/tempo.gleam", 2801). ?DOC(false). -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, Start_date@1 = begin _pipe@6 = Start_date, date_to_calendar_date(_pipe@6) end, _pipe@7 = do_period_comprising_months( [], {month_year, erlang:element(3, Start_date@1), erlang:element(2, Start_date@1)}, End_date ), lists:reverse(_pipe@7). -file("src/tempo.gleam", 2979). ?DOC(false). -spec get_naive_datetime_format_str(naive_date_time_format()) -> binary(). get_naive_datetime_format_str(Format) -> case Format of naive_i_s_o8601_seconds -> <<"YYYY-MM-DDTHH:mm:ss"/utf8>>; naive_i_s_o8601_milli -> <<"YYYY-MM-DDTHH:mm:ss.SSS"/utf8>>; naive_i_s_o8601_micro -> <<"YYYY-MM-DDTHH:mm:ss.SSSS"/utf8>>; {custom_naive, Format@1} -> Format@1; {custom_naive_localised, Format@2, _} -> Format@2; {naive_date_format, i_s_o8601_date} -> <<"YYYY-MM-DD"/utf8>>; {naive_time_format, i_s_o8601_time_seconds} -> <<"HH:mm:ss"/utf8>>; {naive_time_format, i_s_o8601_time_milli} -> <<"HH:mm:ss.SSS"/utf8>>; {naive_time_format, i_s_o8601_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("src/tempo.gleam", 2998). ?DOC(false). -spec get_time_format_str(time_format()) -> binary(). get_time_format_str(Format) -> case Format of i_s_o8601_time_seconds -> <<"HH:mm:ss"/utf8>>; i_s_o8601_time_milli -> <<"HH:mm:ss.SSS"/utf8>>; i_s_o8601_time_micro -> <<"HH:mm:ss.SSSS"/utf8>>; {custom_time, Format@1} -> Format@1; {custom_time_localised, Format@2, _} -> Format@2 end. -file("src/tempo.gleam", 3009). ?DOC(false). -spec get_date_format_str(date_format()) -> binary(). get_date_format_str(Format) -> case Format of i_s_o8601_date -> <<"YYYY-MM-DD"/utf8>>; {custom_date, Format@1} -> Format@1; {custom_date_localised, Format@2, _} -> Format@2 end. -file("src/tempo.gleam", 3486). -spec build_time(matched_time()) -> {ok, time()} | {error, nil}. build_time(Matched) -> {matched_time, Hour, Minute, Second, Fraction, Am} = Matched, Hour@1 = case Am of {some, Am@1} -> adjust_12_hour_to_24_hour(Hour, Am@1); none -> Hour end, gleam@result:'try'(case {Second, Fraction} of {none, _} -> {ok, {0, 0}}; {{some, Second@1}, none} -> {ok, {Second@1, 0}}; {{some, Second@2}, {some, {Milli, 3}}} -> {ok, {Second@2, Milli * 1000}}; {{some, Second@3}, {some, {Micro, 6}}} -> {ok, {Second@3, Micro}}; {{some, Second@4}, {some, {Nano, 9}}} -> {ok, {Second@4, Nano div 1000}}; {{some, _}, {some, _}} -> {error, nil} end, fun(_use0) -> {Second@5, Microsecond} = _use0, _pipe = new_time_micro(Hour@1, Minute, Second@5, Microsecond), gleam@result:replace_error(_pipe, nil) end). -file("src/tempo.gleam", 3556). -spec take_period(bitstring()) -> {gleam@option:option(boolean()), bitstring()}. take_period(Input) -> case Input of <<"AM"/utf8, Input@1/binary>> -> {{some, true}, Input@1}; <<"am"/utf8, Input@1/binary>> -> {{some, true}, Input@1}; <<"PM"/utf8, Input@2/binary>> -> {{some, false}, Input@2}; <<"pm"/utf8, Input@2/binary>> -> {{some, false}, Input@2}; Input@3 -> {none, Input@3} end. -file("src/tempo.gleam", 3546). -spec skip_whitespace(bitstring()) -> bitstring(). skip_whitespace(Input) -> case Input of <<" "/utf8, Input@1/binary>> -> skip_whitespace(Input@1); <<"\t"/utf8, Input@1/binary>> -> skip_whitespace(Input@1); <<"\n"/utf8, Input@1/binary>> -> skip_whitespace(Input@1); <<"\r"/utf8, Input@1/binary>> -> skip_whitespace(Input@1); Input@2 -> Input@2 end. -file("src/tempo.gleam", 3539). -spec skip_decimal_point(bitstring()) -> bitstring(). skip_decimal_point(Input) -> case Input of <<"."/utf8, Input@1/binary>> -> Input@1; Input@2 -> Input@2 end. -file("src/tempo.gleam", 3522). -spec skip_time_separators(bitstring(), integer()) -> {ok, bitstring()} | {error, nil}. skip_time_separators(Input, Count) -> case Count =< 0 of true -> {ok, Input}; false -> case Input of <<":"/utf8, Input@1/binary>> -> skip_time_separators(Input@1, Count - 1); <<"_"/utf8, Input@1/binary>> -> skip_time_separators(Input@1, Count - 1); <<"."/utf8, Input@1/binary>> -> skip_time_separators(Input@1, Count - 1); <<" "/utf8, Input@1/binary>> -> skip_time_separators(Input@1, Count - 1); <<"\t"/utf8, Input@1/binary>> -> skip_time_separators(Input@1, Count - 1); <<"\n"/utf8, Input@1/binary>> -> skip_time_separators(Input@1, Count - 1); <<"\r"/utf8, Input@1/binary>> -> skip_time_separators(Input@1, Count - 1); _ -> {error, nil} end end. -file("src/tempo.gleam", 3513). ?DOC( " Matches an hour or a minute, which may be written with or without a\n" " leading zero.\n" ). -spec take_clock_number( bitstring(), fun((integer(), bitstring()) -> {ok, ESG} | {error, nil}) ) -> {ok, ESG} | {error, nil}. take_clock_number(Input, Continue) -> gtempo@internal:backtrack( [2, 1], fun(Digits) -> gleam@result:'try'( gtempo@internal:take_digits(Input, Digits), fun(_use0) -> {Number, Input@1} = _use0, Continue(Number, Input@1) end ) end ). -file("src/tempo.gleam", 3453). ?DOC( " Matches a time like `13:42:11.314`, `1:42 PM`, or `134211`. Everything\n" " after the minute is optional.\n" ). -spec match_time(bitstring()) -> {ok, {matched_time(), bitstring()}} | {error, nil}. match_time(Input) -> take_clock_number( Input, fun(Hour, Input@1) -> gtempo@internal:backtrack( [1, 0], fun(Separators) -> gleam@result:'try'( skip_time_separators(Input@1, Separators), fun(Input@2) -> take_clock_number( Input@2, fun(Minute, Input@3) -> Input@4 = begin _pipe = skip_time_separators(Input@3, 1), gleam@result:unwrap(_pipe, Input@3) end, {Second, Second_digits, Input@5} = gtempo@internal:take_digits_up_to( Input@4, 2 ), Input@6 = skip_decimal_point(Input@5), {Fraction, Fraction_digits, Input@7} = gtempo@internal:take_digits_up_to( Input@6, 9 ), Input@8 = skip_whitespace(Input@7), {Am, Input@9} = take_period(Input@8), {ok, {{matched_time, Hour, Minute, case Second_digits of 0 -> none; _ -> {some, Second} end, case Fraction_digits of 0 -> none; _ -> {some, {Fraction, Fraction_digits}} end, Am}, Input@9}} end ) end ) end ) end ). -file("src/tempo.gleam", 3200). ?DOC( " Looks for the leftmost run of characters that `matcher` accepts and that\n" " `build` can make a real value out of, returning that value and the input\n" " with those characters cut out of it.\n" "\n" " Text that is shaped like a date or a time but does not describe one, such\n" " as `2024 00:00`, is left in the input for a later pattern to make sense of.\n" ). -spec scan_for( bitstring(), fun((bitstring()) -> {ok, {EQP, bitstring()}} | {error, nil}), fun((EQP) -> {ok, EQS} | {error, nil}) ) -> {gleam@option:option(EQS), bitstring()}. scan_for(Input, Matcher, Build) -> case gtempo@internal:scan(Input, Matcher) of {error, nil} -> {none, Input}; {ok, {Matched, Rest}} -> case Build(Matched) of {ok, Value} -> {{some, Value}, Rest}; {error, nil} -> {none, Input} end end. -file("src/tempo.gleam", 3230). -spec scan_time(bitstring()) -> {gleam@option:option(time()), bitstring()}. scan_time(Input) -> scan_for(Input, fun match_time/1, fun build_time/1). -file("src/tempo.gleam", 3412). -spec find_utc_designator(bitstring(), integer(), boolean()) -> {ok, integer()} | {error, nil}. find_utc_designator(Input, At, After_letter) -> case Input of <> -> Is_designator = case {After_letter, Byte, Rest} of {true, _, _} -> false; {false, 16#5A, <>} -> not gtempo@internal:is_letter(Next); {false, 16#7A, <>} -> not gtempo@internal:is_letter(Next); {false, 16#5A, _} -> true; {false, 16#7A, _} -> true; {false, _, _} -> false end, case Is_designator of true -> {ok, At}; false -> find_utc_designator( Rest, At + 1, gtempo@internal:is_letter(Byte) ) end; _ -> {error, nil} end. -file("src/tempo.gleam", 3400). ?DOC( " Finds a `Z` standing on its own, which means UTC. A `Z` with a letter on\n" " either side of it is part of a word, not an offset.\n" ). -spec scan_utc_designator(bitstring()) -> {gleam@option:option(offset()), bitstring()}. scan_utc_designator(Input) -> case find_utc_designator(Input, 0, false) of {error, nil} -> {none, Input}; {ok, At} -> Size = erlang:byte_size(Input), Before@1 = case gleam_stdlib:bit_array_slice(Input, 0, At) of {ok, Before} -> Before; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"tempo"/utf8>>, function => <<"scan_utc_designator"/utf8>>, line => 3405, value => _assert_fail, start => 97519, 'end' => 97572, pattern_start => 97530, pattern_end => 97540}) end, After@1 = case gleam_stdlib:bit_array_slice( Input, At + 1, (Size - At) - 1 ) of {ok, After} -> After; _assert_fail@1 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"tempo"/utf8>>, function => <<"scan_utc_designator"/utf8>>, line => 3406, value => _assert_fail@1, start => 97579, 'end' => 97647, pattern_start => 97590, pattern_end => 97599}) end, {{some, {offset, 0}}, <>} end. -file("src/tempo.gleam", 3379). -spec build_offset(integer()) -> {ok, offset()} | {error, nil}. build_offset(Minutes) -> new_offset(duration_minutes(Minutes)). -file("src/tempo.gleam", 3391). -spec skip_colon(bitstring()) -> bitstring(). skip_colon(Input) -> case Input of <<":"/utf8, Input@1/binary>> -> Input@1; Input@2 -> Input@2 end. -file("src/tempo.gleam", 3383). -spec take_offset_direction(bitstring()) -> {ok, {boolean(), bitstring()}} | {error, nil}. take_offset_direction(Input) -> case Input of <<"-"/utf8, Input@1/binary>> -> {ok, {true, Input@1}}; <<"+"/utf8, Input@2/binary>> -> {ok, {false, Input@2}}; _ -> {error, nil} end. -file("src/tempo.gleam", 3362). ?DOC( " Matches an offset from UTC like `-04:00`, `+0530`, or `-05`, returning how\n" " many minutes it is.\n" ). -spec match_offset(bitstring()) -> {ok, {integer(), bitstring()}} | {error, nil}. match_offset(Input) -> gleam@result:'try'( take_offset_direction(Input), fun(_use0) -> {Is_negative, Input@1} = _use0, gleam@result:'try'( gtempo@internal:take_digits(Input@1, 2), fun(_use0@1) -> {Hours, Input@2} = _use0@1, Input@3 = skip_colon(Input@2), {Minutes, _, Input@4} = gtempo@internal:take_digits_up_to( Input@3, 2 ), Minutes@1 = (Hours * 60) + Minutes, {ok, {case Is_negative of true -> - Minutes@1; false -> Minutes@1 end, Input@4}} end ) end ). -file("src/tempo.gleam", 3223). -spec scan_offset(bitstring()) -> {gleam@option:option(offset()), bitstring()}. scan_offset(Input) -> case scan_for(Input, fun match_offset/1, fun build_offset/1) of {{some, Offset}, Input@1} -> {{some, Offset}, Input@1}; {none, Input@2} -> scan_utc_designator(Input@2) end. -file("src/tempo.gleam", 3259). -spec build_date({integer(), integer(), integer()}) -> {ok, date()} | {error, nil}. build_date(Parts) -> {Year, Month, Day} = Parts, _pipe = new_date(Year, Month, Day), gleam@result:replace_error(_pipe, nil). -file("src/tempo.gleam", 3329). -spec skip_date_separators(bitstring(), integer()) -> {ok, bitstring()} | {error, nil}. skip_date_separators(Input, Count) -> case Count =< 0 of true -> {ok, Input}; false -> case Input of <<"-"/utf8, Input@1/binary>> -> skip_date_separators(Input@1, Count - 1); <<"_"/utf8, Input@1/binary>> -> skip_date_separators(Input@1, Count - 1); <<"/"/utf8, Input@1/binary>> -> skip_date_separators(Input@1, Count - 1); <<"."/utf8, Input@1/binary>> -> skip_date_separators(Input@1, Count - 1); <<","/utf8, Input@1/binary>> -> skip_date_separators(Input@1, Count - 1); <<" "/utf8, Input@1/binary>> -> skip_date_separators(Input@1, Count - 1); <<"\t"/utf8, Input@1/binary>> -> skip_date_separators(Input@1, Count - 1); <<"\n"/utf8, Input@1/binary>> -> skip_date_separators(Input@1, Count - 1); <<"\r"/utf8, Input@1/binary>> -> skip_date_separators(Input@1, Count - 1); _ -> {error, nil} end end. -file("src/tempo.gleam", 3350). ?DOC( " Skips the `st` of `21st` and its friends, which say nothing the day did\n" " not already say.\n" ). -spec skip_ordinal_suffix(bitstring()) -> bitstring(). skip_ordinal_suffix(Input) -> case Input of <<"st"/utf8, Input@1/binary>> -> Input@1; <<"nd"/utf8, Input@1/binary>> -> Input@1; <<"rd"/utf8, Input@1/binary>> -> Input@1; <<"th"/utf8, Input@1/binary>> -> Input@1; Input@2 -> Input@2 end. -file("src/tempo.gleam", 3270). ?DOC( " Matches a number of one or two digits, preceded by up to two of the\n" " characters that dates are commonly separated by.\n" "\n" " Both the separators and the digits are matched greedily, backtracking into\n" " shorter matches when what comes after them does not fit, so that a date\n" " like `2024-6-21` is read the same way a regular expression would read it.\n" ). -spec take_separated_number( bitstring(), fun((integer(), bitstring()) -> {ok, ERF} | {error, nil}) ) -> {ok, ERF} | {error, nil}. take_separated_number(Input, Continue) -> gtempo@internal:backtrack( [2, 1, 0], fun(Separators) -> gleam@result:'try'( skip_date_separators(Input, Separators), fun(Input@1) -> gtempo@internal:backtrack( [2, 1], fun(Digits) -> gleam@result:'try'( gtempo@internal:take_digits(Input@1, Digits), fun(_use0) -> {Number, Input@2} = _use0, Continue(Number, Input@2) end ) end ) end ) end ). -file("src/tempo.gleam", 3297). -spec take_month_name(bitstring()) -> {ok, {integer(), bitstring()}} | {error, nil}. take_month_name(Input) -> case Input of <<"January"/utf8, Input@1/binary>> -> {ok, {1, Input@1}}; <<"january"/utf8, Input@1/binary>> -> {ok, {1, Input@1}}; <<"Jan"/utf8, Input@2/binary>> -> {ok, {1, Input@2}}; <<"jan"/utf8, Input@2/binary>> -> {ok, {1, Input@2}}; <<"February"/utf8, Input@3/binary>> -> {ok, {2, Input@3}}; <<"february"/utf8, Input@3/binary>> -> {ok, {2, Input@3}}; <<"Feb"/utf8, Input@4/binary>> -> {ok, {2, Input@4}}; <<"feb"/utf8, Input@4/binary>> -> {ok, {2, Input@4}}; <<"March"/utf8, Input@5/binary>> -> {ok, {3, Input@5}}; <<"march"/utf8, Input@5/binary>> -> {ok, {3, Input@5}}; <<"Mar"/utf8, Input@6/binary>> -> {ok, {3, Input@6}}; <<"mar"/utf8, Input@6/binary>> -> {ok, {3, Input@6}}; <<"April"/utf8, Input@7/binary>> -> {ok, {4, Input@7}}; <<"april"/utf8, Input@7/binary>> -> {ok, {4, Input@7}}; <<"Apr"/utf8, Input@8/binary>> -> {ok, {4, Input@8}}; <<"apr"/utf8, Input@8/binary>> -> {ok, {4, Input@8}}; <<"May"/utf8, Input@9/binary>> -> {ok, {5, Input@9}}; <<"may"/utf8, Input@9/binary>> -> {ok, {5, Input@9}}; <<"June"/utf8, Input@10/binary>> -> {ok, {6, Input@10}}; <<"june"/utf8, Input@10/binary>> -> {ok, {6, Input@10}}; <<"Jun"/utf8, Input@11/binary>> -> {ok, {6, Input@11}}; <<"jun"/utf8, Input@11/binary>> -> {ok, {6, Input@11}}; <<"July"/utf8, Input@12/binary>> -> {ok, {7, Input@12}}; <<"july"/utf8, Input@12/binary>> -> {ok, {7, Input@12}}; <<"Jul"/utf8, Input@13/binary>> -> {ok, {7, Input@13}}; <<"jul"/utf8, Input@13/binary>> -> {ok, {7, Input@13}}; <<"August"/utf8, Input@14/binary>> -> {ok, {8, Input@14}}; <<"august"/utf8, Input@14/binary>> -> {ok, {8, Input@14}}; <<"Aug"/utf8, Input@15/binary>> -> {ok, {8, Input@15}}; <<"aug"/utf8, Input@15/binary>> -> {ok, {8, Input@15}}; <<"September"/utf8, Input@16/binary>> -> {ok, {9, Input@16}}; <<"september"/utf8, Input@16/binary>> -> {ok, {9, Input@16}}; <<"Sep"/utf8, Input@17/binary>> -> {ok, {9, Input@17}}; <<"sep"/utf8, Input@17/binary>> -> {ok, {9, Input@17}}; <<"October"/utf8, Input@18/binary>> -> {ok, {10, Input@18}}; <<"october"/utf8, Input@18/binary>> -> {ok, {10, Input@18}}; <<"Oct"/utf8, Input@19/binary>> -> {ok, {10, Input@19}}; <<"oct"/utf8, Input@19/binary>> -> {ok, {10, Input@19}}; <<"November"/utf8, Input@20/binary>> -> {ok, {11, Input@20}}; <<"november"/utf8, Input@20/binary>> -> {ok, {11, Input@20}}; <<"Nov"/utf8, Input@21/binary>> -> {ok, {11, Input@21}}; <<"nov"/utf8, Input@21/binary>> -> {ok, {11, Input@21}}; <<"December"/utf8, Input@22/binary>> -> {ok, {12, Input@22}}; <<"december"/utf8, Input@22/binary>> -> {ok, {12, Input@22}}; <<"Dec"/utf8, Input@23/binary>> -> {ok, {12, Input@23}}; <<"dec"/utf8, Input@23/binary>> -> {ok, {12, Input@23}}; _ -> {error, nil} end. -file("src/tempo.gleam", 3283). ?DOC( " Matches a month written as a number, or written out in full or shortened,\n" " in either title case or lower case.\n" ). -spec take_month( bitstring(), fun((integer(), bitstring()) -> {ok, ERK} | {error, nil}) ) -> {ok, ERK} | {error, nil}. take_month(Input, Continue) -> gleam@result:try_recover( begin gtempo@internal:backtrack( [2, 1], fun(Digits) -> gleam@result:'try'( gtempo@internal:take_digits(Input, Digits), fun(_use0) -> {Month, Input@1} = _use0, Continue(Month, Input@1) end ) end ) end, fun(_) -> gleam@result:'try'( take_month_name(Input), fun(_use0@1) -> {Month@1, Input@2} = _use0@1, Continue(Month@1, Input@2) end ) end ). -file("src/tempo.gleam", 3247). ?DOC( " Matches a date written with the month first, like `06/21/2024` or\n" " `June 21st, 2024`.\n" ). -spec match_written_date(bitstring()) -> {ok, {{integer(), integer(), integer()}, bitstring()}} | {error, nil}. match_written_date(Input) -> take_month( Input, fun(Month, Input@1) -> take_separated_number( Input@1, fun(Day, Input@2) -> Input@3 = skip_ordinal_suffix(Input@2), gtempo@internal:backtrack( [2, 1, 0], fun(Separators) -> gleam@result:'try'( skip_date_separators(Input@3, Separators), fun(Input@4) -> gleam@result:map( gtempo@internal:take_digits(Input@4, 4), fun(_use0) -> {Year, Input@5} = _use0, {{Year, Month, Day}, Input@5} end ) end ) end ) end ) end ). -file("src/tempo.gleam", 3236). ?DOC( " Matches a date written with the year first, like `2024-06-21`, `2024.6.21`,\n" " or `20240621`.\n" ). -spec match_numeric_date(bitstring()) -> {ok, {{integer(), integer(), integer()}, bitstring()}} | {error, nil}. match_numeric_date(Input) -> gleam@result:'try'( gtempo@internal:take_digits(Input, 4), fun(_use0) -> {Year, Input@1} = _use0, take_separated_number( Input@1, fun(Month, Input@2) -> take_separated_number( Input@2, fun(Day, Input@3) -> {ok, {{Year, Month, Day}, Input@3}} end ) end ) end ). -file("src/tempo.gleam", 3215). -spec scan_date(bitstring()) -> {gleam@option:option(date()), bitstring()}. scan_date(Input) -> case scan_for(Input, fun match_numeric_date/1, fun build_date/1) of {{some, Date}, Input@1} -> {{some, Date}, Input@1}; {none, Input@2} -> scan_for(Input@2, fun match_written_date/1, fun build_date/1) end. -file("src/tempo.gleam", 3172). ?DOC( " Tries to parse a given date string without a known format. It will not\n" " parse two digit years and will assume the month always comes before the\n" " day in a date. Always prefer to use a module's specific `parse` function\n" " when possible.\n" "\n" " Using pattern matching, you can explicitly specify what to with the\n" " missing values from the input. Many libaries will assume a missing time\n" " value means 00:00:00 or a missing offset means UTC. This design\n" " lets the user decide how fallbacks are handled.\n" "\n" " ## Example\n" "\n" " ```gleam\n" " case tempo.parse_any(\"06/21/2024 at 01:42:11 PM\") {\n" " #(Some(date), Some(time), Some(offset)) ->\n" " datetime.new(date, time, offset)\n" "\n" " #(Some(date), Some(time), None) ->\n" " datetime.new(date, time, offset.local())\n" "\n" " _ -> datetime.now_local()\n" " }\n" " // -> datetime.literal(\"2024-06-21T13:42:11-04:00\")\n" " ```\n" "\n" " ```gleam\n" " tempo.parse_any(\"2024.06.21 11:32 AM -0400\")\n" " // -> #(\n" " // Some(date.literal(\"2024-06-21\")),\n" " // Some(time.literal(\"11:32:00\")),\n" " // Some(offset.literal(\"-04:00\"))\n" " // )\n" " ```\n" "\n" " ```gleam\n" " tempo.parse_any(\"Dec 25, 2024 at 6:00 AM\")\n" " // -> #(\n" " // Some(date.literal(\"2024-12-25\")),\n" " // Some(time.literal(\"06:00:00\")),\n" " // None\n" " // )\n" " ```\n" ). -spec parse_any(binary()) -> {gleam@option:option(date()), gleam@option:option(time()), gleam@option:option(offset())}. parse_any(Str) -> Input = gleam_stdlib:identity(Str), gleam@bool:guard( gtempo@internal:has_digit_run(Input, 10), {none, none, none}, fun() -> {Date, Input@1} = scan_date(Input), {Offset, Input@2} = scan_offset(Input@1), {Time, _} = scan_time(Input@2), {Date, Time, Offset} end ). -file("src/tempo.gleam", 3616). ?DOC(" Consumes the given literal text from the front of the input.\n"). -spec consume_literal(binary(), bitstring()) -> {ok, bitstring()} | {error, nil}. consume_literal(Literal, Input) -> Literal@1 = gleam_stdlib:identity(Literal), Length = erlang:byte_size(Literal@1), case gleam_stdlib:bit_array_slice(Input, 0, Length) =:= {ok, Literal@1} of true -> gtempo@internal:skip(Input, Length); false -> {error, nil} end. -file("src/tempo.gleam", 3794). ?DOC( " Takes an offset that has already been vouched for by its directive, so it\n" " is handed on as-is for `offset_from_string` to make sense of.\n" ). -spec consume_offset_text(bitstring(), integer()) -> {datetime_part(), bitstring()}. consume_offset_text(Input, Length) -> {Offset, Input@1} = gtempo@internal:take_string_up_to(Input, Length), {{offset_str, Offset}, Input@1}. -file("src/tempo.gleam", 3829). ?DOC(" Matches the `Z` that stands for an offset of UTC.\n"). -spec take_utc_designator(bitstring()) -> {ok, bitstring()} | {error, nil}. take_utc_designator(Input) -> case Input of <<"Z"/utf8, Input@1/binary>> -> {ok, Input@1}; <<"z"/utf8, Input@1/binary>> -> {ok, Input@1}; _ -> {error, nil} end. -file("src/tempo.gleam", 3836). -spec take_offset_sign(bitstring()) -> {ok, bitstring()} | {error, nil}. take_offset_sign(Input) -> case Input of <<"+"/utf8, Input@1/binary>> -> {ok, Input@1}; <<"-"/utf8, Input@1/binary>> -> {ok, Input@1}; _ -> {error, nil} end. -file("src/tempo.gleam", 3822). ?DOC(" Matches `+hh`.\n"). -spec take_hour_offset(bitstring()) -> {ok, bitstring()} | {error, nil}. take_hour_offset(Input) -> gleam@result:'try'( take_offset_sign(Input), fun(Input@1) -> gleam@result:map( gtempo@internal:take_digits(Input@1, 2), fun(_use0) -> {_, Input@2} = _use0, Input@2 end ) end ). -file("src/tempo.gleam", 3815). ?DOC(" Matches `+hhmm`.\n"). -spec take_hour_minute_offset(bitstring()) -> {ok, bitstring()} | {error, nil}. take_hour_minute_offset(Input) -> gleam@result:'try'( take_offset_sign(Input), fun(Input@1) -> gleam@result:map( gtempo@internal:take_digits(Input@1, 4), fun(_use0) -> {_, Input@2} = _use0, Input@2 end ) end ). -file("src/tempo.gleam", 3803). ?DOC(" Matches `+hh:mm`.\n"). -spec take_hour_colon_minute_offset(bitstring()) -> {ok, bitstring()} | {error, nil}. take_hour_colon_minute_offset(Input) -> gleam@result:'try'( take_offset_sign(Input), fun(Input@1) -> gleam@result:'try'( gtempo@internal:take_digits(Input@1, 2), fun(_use0) -> {_, Input@2} = _use0, gleam@result:'try'( gtempo@internal:accept_byte(Input@2, 16#3A), fun(Input@3) -> gleam@result:map( gtempo@internal:take_digits(Input@3, 2), fun(_use0@1) -> {_, Input@4} = _use0@1, Input@4 end ) end ) end ) end ). -file("src/tempo.gleam", 3851). -spec consume_two_digits(bitstring(), fun((integer()) -> datetime_part())) -> {ok, {datetime_part(), bitstring()}} | {error, nil}. consume_two_digits(Input, Constructor) -> gleam@result:map( gtempo@internal:take_digits(Input, 2), fun(_use0) -> {Value, Input@1} = _use0, {Constructor(Value), Input@1} end ). -file("src/tempo.gleam", 3843). -spec consume_one_or_two_digits( bitstring(), fun((integer()) -> datetime_part()) ) -> {ok, {datetime_part(), bitstring()}} | {error, nil}. consume_one_or_two_digits(Input, Constructor) -> gleam@result:map( gtempo@internal:take_one_or_two_digits(Input), fun(_use0) -> {Value, Input@1} = _use0, {Constructor(Value), Input@1} end ). -file("src/tempo.gleam", 3782). ?DOC( " Consumes whichever of the given literals comes next in the input, keeping\n" " none of it.\n" ). -spec consume_any(list(binary()), bitstring()) -> {ok, {datetime_part(), bitstring()}} | {error, nil}. consume_any(Literals, Input) -> gleam@result:map( gtempo@internal:backtrack( Literals, fun(_capture) -> consume_literal(_capture, Input) end ), fun(Input@1) -> {passthrough, Input@1} end ). -file("src/tempo.gleam", 3629). -spec consume_part(binary(), bitstring()) -> {ok, {datetime_part(), bitstring()}} | {error, binary()}. consume_part(Directive, Input) -> _pipe@1 = case Directive of <<"YY"/utf8>> -> gleam@result:map( gtempo@internal:take_digits(Input, 2), fun(_use0) -> {Year, Input@1} = _use0, Current_year = tempo_ffi:current_year(), Current_century = (Current_year div 100) * 100, case Year > (Current_year rem 100) of true -> {{year, (Current_century - 100) + Year}, Input@1}; false -> {{year, Current_century + Year}, Input@1} end end ); <<"YYYY"/utf8>> -> gleam@result:map( gtempo@internal:take_digits(Input, 4), fun(_use0@1) -> {Year@1, Input@2} = _use0@1, {{year, Year@1}, Input@2} end ); <<"M"/utf8>> -> consume_one_or_two_digits( Input, fun(Field@0) -> {month, Field@0} end ); <<"MM"/utf8>> -> consume_two_digits(Input, fun(Field@0) -> {month, Field@0} end); <<"MMM"/utf8>> -> case Input of <<"Jan"/utf8, Input@3/binary>> -> {ok, {{month, 1}, Input@3}}; <<"Feb"/utf8, Input@4/binary>> -> {ok, {{month, 2}, Input@4}}; <<"Mar"/utf8, Input@5/binary>> -> {ok, {{month, 3}, Input@5}}; <<"Apr"/utf8, Input@6/binary>> -> {ok, {{month, 4}, Input@6}}; <<"May"/utf8, Input@7/binary>> -> {ok, {{month, 5}, Input@7}}; <<"Jun"/utf8, Input@8/binary>> -> {ok, {{month, 6}, Input@8}}; <<"Jul"/utf8, Input@9/binary>> -> {ok, {{month, 7}, Input@9}}; <<"Aug"/utf8, Input@10/binary>> -> {ok, {{month, 8}, Input@10}}; <<"Sep"/utf8, Input@11/binary>> -> {ok, {{month, 9}, Input@11}}; <<"Oct"/utf8, Input@12/binary>> -> {ok, {{month, 10}, Input@12}}; <<"Nov"/utf8, Input@13/binary>> -> {ok, {{month, 11}, Input@13}}; <<"Dec"/utf8, Input@14/binary>> -> {ok, {{month, 12}, Input@14}}; _ -> {error, nil} end; <<"MMMM"/utf8>> -> case Input of <<"January"/utf8, Input@15/binary>> -> {ok, {{month, 1}, Input@15}}; <<"February"/utf8, Input@16/binary>> -> {ok, {{month, 2}, Input@16}}; <<"March"/utf8, Input@17/binary>> -> {ok, {{month, 3}, Input@17}}; <<"April"/utf8, Input@18/binary>> -> {ok, {{month, 4}, Input@18}}; <<"May"/utf8, Input@19/binary>> -> {ok, {{month, 5}, Input@19}}; <<"June"/utf8, Input@20/binary>> -> {ok, {{month, 6}, Input@20}}; <<"July"/utf8, Input@21/binary>> -> {ok, {{month, 7}, Input@21}}; <<"August"/utf8, Input@22/binary>> -> {ok, {{month, 8}, Input@22}}; <<"September"/utf8, Input@23/binary>> -> {ok, {{month, 9}, Input@23}}; <<"October"/utf8, Input@24/binary>> -> {ok, {{month, 10}, Input@24}}; <<"November"/utf8, Input@25/binary>> -> {ok, {{month, 11}, Input@25}}; <<"December"/utf8, Input@26/binary>> -> {ok, {{month, 12}, Input@26}}; _ -> {error, nil} end; <<"D"/utf8>> -> consume_one_or_two_digits(Input, fun(Field@0) -> {day, Field@0} end); <<"DD"/utf8>> -> consume_two_digits(Input, fun(Field@0) -> {day, Field@0} end); <<"d"/utf8>> -> consume_any( [<<"0"/utf8>>, <<"1"/utf8>>, <<"2"/utf8>>, <<"3"/utf8>>, <<"4"/utf8>>, <<"5"/utf8>>, <<"6"/utf8>>], Input ); <<"dd"/utf8>> -> consume_any( [<<"Su"/utf8>>, <<"Mo"/utf8>>, <<"Tu"/utf8>>, <<"We"/utf8>>, <<"Th"/utf8>>, <<"Fr"/utf8>>, <<"Sa"/utf8>>], Input ); <<"ddd"/utf8>> -> consume_any( [<<"Sun"/utf8>>, <<"Mon"/utf8>>, <<"Tue"/utf8>>, <<"Wed"/utf8>>, <<"Thu"/utf8>>, <<"Fri"/utf8>>, <<"Sat"/utf8>>], Input ); <<"dddd"/utf8>> -> consume_any( [<<"Sunday"/utf8>>, <<"Monday"/utf8>>, <<"Tuesday"/utf8>>, <<"Wednesday"/utf8>>, <<"Thursday"/utf8>>, <<"Friday"/utf8>>, <<"Saturday"/utf8>>], Input ); <<"H"/utf8>> -> consume_one_or_two_digits( Input, fun(Field@0) -> {hour, Field@0} end ); <<"HH"/utf8>> -> consume_two_digits(Input, fun(Field@0) -> {hour, Field@0} end); <<"h"/utf8>> -> consume_one_or_two_digits( Input, fun(Field@0) -> {twelve_hour, Field@0} end ); <<"hh"/utf8>> -> consume_two_digits( Input, fun(Field@0) -> {twelve_hour, Field@0} end ); <<"a"/utf8>> -> case Input of <<"am"/utf8, Input@27/binary>> -> {ok, {a_m_period, Input@27}}; <<"pm"/utf8, Input@28/binary>> -> {ok, {p_m_period, Input@28}}; _ -> {error, nil} end; <<"A"/utf8>> -> case Input of <<"AM"/utf8, Input@29/binary>> -> {ok, {a_m_period, Input@29}}; <<"PM"/utf8, Input@30/binary>> -> {ok, {p_m_period, Input@30}}; _ -> {error, nil} end; <<"m"/utf8>> -> consume_one_or_two_digits( Input, fun(Field@0) -> {minute, Field@0} end ); <<"mm"/utf8>> -> consume_two_digits(Input, fun(Field@0) -> {minute, Field@0} end); <<"s"/utf8>> -> consume_one_or_two_digits( Input, fun(Field@0) -> {second, Field@0} end ); <<"ss"/utf8>> -> consume_two_digits(Input, fun(Field@0) -> {second, Field@0} end); <<"SSS"/utf8>> -> gleam@result:map( gtempo@internal:take_digits(Input, 3), fun(_use0@2) -> {Milli, Input@31} = _use0@2, {{millisecond, Milli}, Input@31} end ); <<"SSSS"/utf8>> -> gleam@result:map( gtempo@internal:take_digits(Input, 6), fun(_use0@3) -> {Micro, Input@32} = _use0@3, {{microsecond, Micro}, Input@32} end ); <<"z"/utf8>> -> gleam@result:map( gtempo@internal:backtrack( [fun take_hour_colon_minute_offset/1, fun take_hour_minute_offset/1, fun take_hour_offset/1, fun take_utc_designator/1], fun(_capture) -> gtempo@internal:take_matched(Input, _capture) end ), fun(_use0@4) -> {Offset, Input@33} = _use0@4, {{offset_str, Offset}, Input@33} end ); <<"zz"/utf8>> -> case Input of <<"Z"/utf8>> -> {ok, {{offset_str, <<"Z"/utf8>>}, <<>>}}; <<"z"/utf8>> -> {ok, {{offset_str, <<"z"/utf8>>}, <<>>}}; _ -> {ok, consume_offset_text(Input, 6)} end; <<"Z"/utf8>> -> {ok, consume_offset_text(Input, 6)}; <<"ZZ"/utf8>> -> {ok, consume_offset_text(Input, 5)}; <<"GMT"/utf8>> -> case Input of <<"GMT"/utf8>> -> {ok, {{offset_str, <<"Z"/utf8>>}, <<>>}}; _ -> {error, nil} end; Literal -> _pipe = consume_literal(Literal, Input), gleam@result:map( _pipe, fun(Input@34) -> {passthrough, Input@34} end ) end, gleam@result:replace_error( _pipe@1, <<"Unable to parse directive "/utf8, Directive/binary>> ). -file("src/tempo.gleam", 3586). -spec do_consume_format( list(format_token()), bitstring(), list(datetime_part()) ) -> {ok, list(datetime_part())} | {error, binary()}. do_consume_format(Tokens, Input, Consumed) -> case Tokens of [] -> {ok, Consumed}; [{directive, Directive} | Tokens@1] -> case consume_part(Directive, Input) of {ok, {Part, Input@1}} -> do_consume_format(Tokens@1, Input@1, [Part | Consumed]); {error, Error} -> {error, Error} end; [{escaped, Literal} | Tokens@2] -> case consume_literal(Literal, Input) of {ok, Input@2} -> do_consume_format( Tokens@2, Input@2, [passthrough | Consumed] ); {error, nil} -> {error, <<<<"Input does not match expected escape sequence \""/utf8, Literal/binary>>/binary, "\""/utf8>>} end end. -file("src/tempo.gleam", 3582). ?DOC(false). -spec consume_format(binary(), binary()) -> {ok, list(datetime_part())} | {error, binary()}. consume_format(Str, Fmt) -> do_consume_format(tokenise_format(Fmt), gleam_stdlib:identity(Str), []). -file("src/tempo.gleam", 3860). ?DOC(false). -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("src/tempo.gleam", 3896). ?DOC(false). -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 a_m_period -> {ok, nil}; _ -> {error, nil} end end ), Pm_period = gleam@list:find_map( Parts, fun(P@3) -> case P@3 of p_m_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("src/tempo.gleam", 3988). ?DOC(false). -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("src/tempo.gleam", 4038). ?DOC(false). -spec freeze_time_ffi(integer(), integer()) -> nil. freeze_time_ffi(Microseconds, Offset_minutes) -> tempo_ffi:freeze_time(Microseconds, Offset_minutes). -file("src/tempo.gleam", 4046). ?DOC(false). -spec unfreeze_time_ffi() -> nil. unfreeze_time_ffi() -> tempo_ffi:unfreeze_time(). -file("src/tempo.gleam", 4051). ?DOC(false). -spec set_reference_time_ffi(integer(), integer(), float()) -> nil. set_reference_time_ffi(Microseconds, Offset_minutes, Speedup) -> tempo_ffi:set_reference_time(Microseconds, Offset_minutes, Speedup). -file("src/tempo.gleam", 4060). ?DOC(false). -spec unset_reference_time_ffi() -> nil. unset_reference_time_ffi() -> tempo_ffi:unset_reference_time(). -file("src/tempo.gleam", 4070). ?DOC(false). -spec set_sleep_warp_ffi(boolean()) -> nil. set_sleep_warp_ffi(Do_warp) -> tempo_ffi:set_sleep_warp(Do_warp). -file("src/tempo.gleam", 4075). ?DOC(false). -spec add_warp_time_ffi(integer()) -> nil. add_warp_time_ffi(Microseconds) -> tempo_ffi:add_warp_time(Microseconds). -file("src/tempo.gleam", 4080). ?DOC(false). -spec reset_warp_time_ffi() -> nil. reset_warp_time_ffi() -> tempo_ffi:reset_warp_time().