-module(tempo). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -define(FILEPATH, "src/tempo.gleam"). -export([instant_get_unique/1, instant_as_unix_seconds/1, instant_as_unix_milli/1, instant_as_unix_micro/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, datetime_get_tz/1, datetime_drop_offset/1, naive_datetime/2, naive_datetime_get_date/1, naive_datetime_get_time/1, naive_datetime_set_offset/2, offset/1, offset_get_minutes/1, offset_to_string/1, validate_offset/1, date/1, date_get_unix_days/1, date_from_unix_seconds/1, date_from_unix_milli/1, date_from_unix_micro/1, instant_as_utc_date/1, instant_as_local_date/1, date_to_day_of_week_number/1, date_to_unix_seconds/1, date_to_unix_milli/1, date_to_unix_micro/1, date_add/2, date_subtract/2, date_days_apart/2, date_compare/2, date_is_earlier/2, date_is_earlier_or_equal/2, date_is_equal/2, date_is_later/2, date_is_later_or_equal/2, month_from_int/1, month_from_short_string/1, month_from_long_string/1, month_to_int/1, month_to_short_string/1, month_to_long_string/1, month_year_to_int/1, month_year_prior/1, month_year_next/1, is_leap_year/1, month_year_days_of/1, month_days_of/2, year_days/1, time/4, time_from_microseconds/1, time_get_hour/1, time_get_minute/1, time_get_second/1, time_get_micro/1, validate_time/4, new_time/3, new_time_milli/4, new_time_micro/4, time_to_calendar_time_of_day/1, time_replace_format/2, adjust_12_hour_to_24_hour/2, time_to_microseconds/1, time_to_parts/1, time_to_string/1, time_from_unix_micro/1, instant_as_utc_time/1, instant_as_local_time/1, instant_as_local_datetime/1, time_compare/2, naive_datetime_compare/2, naive_datetime_is_earlier/2, naive_datetime_is_earlier_or_equal/2, naive_datetime_is_later_or_equal/2, time_is_earlier/2, time_is_earlier_or_equal/2, time_is_equal/2, time_is_later/2, time_is_later_or_equal/2, duration_microseconds/1, instant_difference/2, offset_to_duration/1, time_difference/2, time_to_duration/1, duration_get_microseconds/1, time_add/2, time_subtract/2, duration_seconds_and_nanoseconds/2, duration_as_mintues/1, new_offset/1, duration_minutes/1, duration_days/1, duration_increase/2, naive_datetime_difference/2, duration_absolute/1, duration_inverse/1, duration_decrease/2, duration_is_positive/1, duration_clamp_to_zero/1, duration_as_days/1, duration_as_microseconds/1, period_new_naive/2, period_new_date/2, period_comprising_dates/1, get_datetime_format_str/1, get_naive_datetime_format_str/1, get_time_format_str/1, get_date_format_str/1, find_time/1, now_utc_ffi/0, now_monotonic_ffi/0, now_unique_ffi/0, offset_local_minutes/0, offset_local_micro/0, now/0, instant_since/1, instant_since_formatted/1, compare_utc_date/1, compare_local_date/1, is_utc_date_earlier/1, is_local_date_earlier/1, is_utc_date_earlier_or_equal/1, is_local_date_earlier_or_equal/1, is_utc_date_equal/1, is_local_date_equal/1, is_utc_date_later/1, is_local_date_later/1, is_utc_date_later_or_equal/1, is_local_date_later_or_equal/1, compare_utc_time/1, compare_local_time/1, is_utc_time_earlier/1, is_local_time_earlier/1, is_utc_time_earlier_or_equal/1, is_local_time_earlier_or_equal/1, is_utc_time_equal/1, is_local_time_equal/1, is_utc_time_later/1, is_local_time_later/1, is_utc_time_later_or_equal/1, is_local_time_later_or_equal/1, utc_time_difference_from/1, local_time_difference_from/1, utc_time_since/1, local_time_since/1, utc_time_until/1, local_time_until/1, utc_date_difference_from/1, local_date_difference_from/1, utc_days_since/1, local_days_since/1, utc_days_until/1, local_days_until/1, consume_format/2, freeze_time_ffi/2, unfreeze_time_ffi/0, set_reference_time_ffi/3, unset_reference_time_ffi/0, sleep_ffi/1, sleep/1, set_sleep_warp_ffi/1, add_warp_time_ffi/1, reset_warp_time_ffi/0, now_adjusted/1, instant_as_utc_datetime/1, offset_from_string/1, find_offset/1, date_to_rata_die/1, date_get_year/1, date_to_calendar_date/1, date_get_month_year/1, date_get_month/1, date_get_day/1, date_to_string/1, naive_datetime_to_string/1, datetime_to_string/1, instant_to_utc_string/1, instant_to_local_string/1, date_replace_format/2, date_calendar_from_unix_seconds/1, date_from_rata_die/1, date_calendar_to_unix_days/1, date_from_calendar_date/1, date_from_tuple/1, new_date/3, period_comprising_months/1, parse_any/1, find_date/1, period_get_start_and_end_date_and_time/1, period_as_duration/1, period_contains_naive_datetime/2, datetime_format/2, format_utc/1, format_local/1, datetime_add/2, datetime_to_offset/2, naive_datetime_add/2, naive_datetime_subtract/2, datetime_apply_offset/1, datetime_to_utc/1, datetime_to_tz/2, datetime_to_unix_micro/1, datetime_compare/2, compare/1, datetime_is_earlier/2, is_earlier/1, datetime_is_earlier_or_equal/2, is_earlier_or_equal/1, datetime_is_equal/2, is_equal/1, datetime_is_later_or_equal/2, is_later_or_equal/1, datetime_is_later/2, is_later/1, datetime_difference/2, difference/1, since/1, until/1, datetime_subtract/2, period_new/2, period_contains_datetime/2]). -export_type([instant/0, date_time/0, time_zone_provider/0, naive_date_time/0, offset/0, date/0, month_year/0, time/0, period/0, date_time_format/0, naive_date_time_format/0, date_format/0, time_format/0, locale/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 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", 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", 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", 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", 1087). ?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", 1166). ?DOC(false). -spec naive_datetime(date(), time()) -> naive_date_time(). naive_datetime(Date, Time) -> {naive_date_time, Date, Time}. -file("src/tempo.gleam", 1171). ?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", 1176). ?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", 1181). ?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", 1347). ?DOC(false). -spec offset(integer()) -> offset(). offset(Minutes) -> {offset, Minutes}. -file("src/tempo.gleam", 1352). ?DOC(false). -spec offset_get_minutes(offset()) -> integer(). offset_get_minutes(Offset) -> erlang:element(2, Offset). -file("src/tempo.gleam", 1428). ?DOC(false). -spec offset_to_string(offset()) -> binary(). offset_to_string(Offset) -> {Is_negative, Hours} = case offset_get_minutes(Offset) div 60 of H when H =< 0 -> {true, - H}; H@1 -> {false, H@1} end, Mins = case offset_get_minutes(Offset) rem 60 of M when M < 0 -> - M; M@1 -> M@1 end, case {Is_negative, Hours, Mins} of {_, 0, 0} -> <<"+00:00"/utf8>>; {_, 0, M@2} -> <<"-00:"/utf8, (begin _pipe = erlang:integer_to_binary(M@2), gleam@string:pad_start(_pipe, 2, <<"0"/utf8>>) end)/binary>>; {true, H@2, M@3} -> <<<<<<"-"/utf8, (begin _pipe@1 = erlang:integer_to_binary(H@2), gleam@string:pad_start(_pipe@1, 2, <<"0"/utf8>>) end)/binary>>/binary, ":"/utf8>>/binary, (begin _pipe@2 = erlang:integer_to_binary(M@3), gleam@string:pad_start(_pipe@2, 2, <<"0"/utf8>>) end)/binary>>; {false, H@3, M@4} -> <<<<<<"+"/utf8, (begin _pipe@3 = erlang:integer_to_binary(H@3), gleam@string:pad_start(_pipe@3, 2, <<"0"/utf8>>) end)/binary>>/binary, ":"/utf8>>/binary, (begin _pipe@4 = erlang:integer_to_binary(M@4), gleam@string:pad_start(_pipe@4, 2, <<"0"/utf8>>) end)/binary>> end. -file("src/tempo.gleam", 1459). ?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", 1472). -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", 1511). ?DOC(false). -spec date(integer()) -> date(). date(Unix_days) -> {date, Unix_days}. -file("src/tempo.gleam", 1516). ?DOC(false). -spec date_get_unix_days(date()) -> integer(). date_get_unix_days(Date) -> erlang:element(2, Date). -file("src/tempo.gleam", 1582). ?DOC(false). -spec date_from_unix_seconds(integer()) -> date(). date_from_unix_seconds(Unix_ts) -> {date, Unix_ts div 86400}. -file("src/tempo.gleam", 1587). ?DOC(false). -spec date_from_unix_milli(integer()) -> date(). date_from_unix_milli(Unix_milli) -> {date, Unix_milli div 86400000}. -file("src/tempo.gleam", 1592). ?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", 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", 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", 1689). ?DOC(false). -spec date_to_day_of_week_number(date()) -> integer(). date_to_day_of_week_number(Date) -> (erlang:element(2, Date) + 4) rem 7. -file("src/tempo.gleam", 1662). -spec date_to_day_of_week_short(date()) -> binary(). date_to_day_of_week_short(Date) -> case date_to_day_of_week_number(Date) of 0 -> <<"Sun"/utf8>>; 1 -> <<"Mon"/utf8>>; 2 -> <<"Tue"/utf8>>; 3 -> <<"Wed"/utf8>>; 4 -> <<"Thu"/utf8>>; 5 -> <<"Fri"/utf8>>; 6 -> <<"Sat"/utf8>>; _ -> erlang:error(#{gleam_error => panic, message => <<"Invalid day of week found after modulo by 7"/utf8>>, file => <>, module => <<"tempo"/utf8>>, function => <<"date_to_day_of_week_short"/utf8>>, line => 1671}) end. -file("src/tempo.gleam", 1675). -spec date_to_day_of_week_long(date()) -> binary(). date_to_day_of_week_long(Date) -> case date_to_day_of_week_number(Date) of 0 -> <<"Sunday"/utf8>>; 1 -> <<"Monday"/utf8>>; 2 -> <<"Tuesday"/utf8>>; 3 -> <<"Wednesday"/utf8>>; 4 -> <<"Thursday"/utf8>>; 5 -> <<"Friday"/utf8>>; 6 -> <<"Saturday"/utf8>>; _ -> erlang:error(#{gleam_error => panic, message => <<"Invalid day of week found after modulo by 7"/utf8>>, file => <>, module => <<"tempo"/utf8>>, function => <<"date_to_day_of_week_long"/utf8>>, line => 1684}) end. -file("src/tempo.gleam", 1828). ?DOC(false). -spec date_to_unix_seconds(date()) -> integer(). date_to_unix_seconds(Date) -> erlang:element(2, Date) * 86400. -file("src/tempo.gleam", 1833). ?DOC(false). -spec date_to_unix_milli(date()) -> integer(). date_to_unix_milli(Date) -> erlang:element(2, Date) * 86400000. -file("src/tempo.gleam", 1838). ?DOC(false). -spec date_to_unix_micro(date()) -> integer(). date_to_unix_micro(Date) -> erlang:element(2, Date) * 86400000000. -file("src/tempo.gleam", 1853). ?DOC(false). -spec date_add(date(), integer()) -> date(). date_add(Date, Days) -> {date, erlang:element(2, Date) + Days}. -file("src/tempo.gleam", 1858). ?DOC(false). -spec date_subtract(date(), integer()) -> date(). date_subtract(Date, Days) -> {date, erlang:element(2, Date) - Days}. -file("src/tempo.gleam", 1863). ?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", 1868). ?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", 1873). ?DOC(false). -spec date_is_earlier(date(), date()) -> boolean(). date_is_earlier(A, B) -> date_compare(A, B) =:= lt. -file("src/tempo.gleam", 1878). ?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", 1883). ?DOC(false). -spec date_is_equal(date(), date()) -> boolean(). date_is_equal(A, B) -> date_compare(A, B) =:= eq. -file("src/tempo.gleam", 1888). ?DOC(false). -spec date_is_later(date(), date()) -> boolean(). date_is_later(A, B) -> date_compare(A, B) =:= gt. -file("src/tempo.gleam", 1893). ?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", 1897). -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", 1912). ?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", 1931). ?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", 1950). ?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", 1969). ?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", 1987). ?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", 2005). ?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", 2037). ?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", 2042). ?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", 2060). ?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", 2104). ?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", 2078). ?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", 2023). ?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", 1766). -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", 2120). ?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", 2152). ?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", 2171). ?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", 2186). ?DOC(false). -spec time_from_microseconds(integer()) -> time(). time_from_microseconds(Microseconds) -> {time_of_day, Microseconds}. -file("src/tempo.gleam", 2191). ?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", 2200). ?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", 2214). ?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", 2238). ?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", 2368). -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", 2300). ?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", 2271). ?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", 2280). ?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", 2290). ?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", 2417). ?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", 2427). ?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", 2482). ?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", 2497). ?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", 2506). ?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", 2392). ?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", 2542). ?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", 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", 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", 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", 2553). ?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", 1198). ?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", 1206). ?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", 1214). ?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", 1223). ?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", 2558). ?DOC(false). -spec time_is_earlier(time(), time()) -> boolean(). time_is_earlier(A, B) -> time_compare(A, B) =:= lt. -file("src/tempo.gleam", 2563). ?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", 2568). ?DOC(false). -spec time_is_equal(time(), time()) -> boolean(). time_is_equal(A, B) -> time_compare(A, B) =:= eq. -file("src/tempo.gleam", 2573). ?DOC(false). -spec time_is_later(time(), time()) -> boolean(). time_is_later(A, B) -> time_compare(A, B) =:= gt. -file("src/tempo.gleam", 2578). ?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", 2622). ?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", 1468). ?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", 2492). ?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", 2548). ?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", 2627). ?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", 2583). ?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", 2607). ?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", 2633). ?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", 2639). ?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", 1360). ?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", 2644). ?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", 2649). ?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", 2654). ?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", 1232). ?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", 2670). ?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", 2691). ?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", 2662). ?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", 2704). ?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", 2696). ?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", 2710). ?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", 2715). ?DOC(false). -spec duration_as_microseconds(gleam@time@duration:duration()) -> integer(). duration_as_microseconds(Duration) -> duration_get_microseconds(Duration). -file("src/tempo.gleam", 2744). ?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", 2756). ?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", 2833). -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", 2823). ?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", 3004). ?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", 3024). ?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", 3043). ?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", 3054). ?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", 3677). -spec consume_one_or_two_digits(binary(), fun((integer()) -> ESD)) -> {ok, {ESD, binary()}} | {error, nil}. consume_one_or_two_digits(Str, Constructor) -> case begin _pipe = gleam@string:slice(Str, 0, 2), gleam_stdlib:parse_int(_pipe) end of {ok, Val} -> {ok, {Constructor(Val), gleam@string:drop_start(Str, 2)}}; {error, _} -> case begin _pipe@1 = gleam@string:slice(Str, 0, 1), gleam_stdlib:parse_int(_pipe@1) end of {ok, Val@1} -> {ok, {Constructor(Val@1), gleam@string:drop_start(Str, 1)}}; {error, _} -> {error, nil} end end. -file("src/tempo.gleam", 3688). -spec consume_two_digits(binary(), fun((integer()) -> ESW)) -> {ok, {ESW, binary()}} | {error, nil}. consume_two_digits(Str, Constructor) -> gleam@result:map( begin _pipe = gleam@string:slice(Str, 0, 2), gleam_stdlib:parse_int(_pipe) end, fun(Val) -> {Constructor(Val), gleam@string:drop_start(Str, 2)} end ). -file("src/tempo.gleam", 3731). ?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", 3837). -spec result_guard({ok, EXS} | {error, any()}, EXV, fun((EXS) -> EXV)) -> EXV. result_guard(E, V, Run) -> case E of {error, _} -> V; {ok, Ok} -> Run(Ok) end. -file("src/tempo.gleam", 3851). ?DOC(false). -spec now_utc_ffi() -> integer(). now_utc_ffi() -> tempo_ffi:now(). -file("src/tempo.gleam", 3856). ?DOC(false). -spec now_monotonic_ffi() -> integer(). now_monotonic_ffi() -> tempo_ffi:now_monotonic(). -file("src/tempo.gleam", 3861). ?DOC(false). -spec now_unique_ffi() -> integer(). now_unique_ffi() -> tempo_ffi:now_unique(). -file("src/tempo.gleam", 3871). ?DOC(false). -spec offset_local_minutes() -> integer(). offset_local_minutes() -> tempo_ffi:local_offset(). -file("src/tempo.gleam", 3864). ?DOC(false). -spec offset_local_micro() -> integer(). offset_local_micro() -> tempo_ffi:local_offset() * 60000000. -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", 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", 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", 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", 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", 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", 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", 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", 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", 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", 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", 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", 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", 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", 3421). -spec consume_part(binary(), binary()) -> {ok, {datetime_part(), binary()}} | {error, binary()}. consume_part(Fmt, Str) -> _pipe@15 = case Fmt of <<"YY"/utf8>> -> gleam@result:map( begin _pipe = gleam@string:slice(Str, 0, 2), gleam_stdlib:parse_int(_pipe) end, fun(Val) -> Current_year = tempo_ffi:current_year(), Current_century = (Current_year div 100) * 100, Current_two_year_date = Current_year rem 100, case Val > Current_two_year_date of true -> {{year, (Current_century - 100) + Val}, gleam@string:drop_start(Str, 2)}; false -> {{year, Current_century + Val}, gleam@string:drop_start(Str, 2)} end end ); <<"YYYY"/utf8>> -> gleam@result:map( begin _pipe@1 = gleam@string:slice(Str, 0, 4), gleam_stdlib:parse_int(_pipe@1) end, fun(Year) -> {{year, Year}, gleam@string:drop_start(Str, 4)} end ); <<"M"/utf8>> -> consume_one_or_two_digits(Str, fun(Field@0) -> {month, Field@0} end); <<"MM"/utf8>> -> consume_two_digits(Str, fun(Field@0) -> {month, Field@0} end); <<"MMM"/utf8>> -> case Str of <<"Jan"/utf8, Rest/binary>> -> {ok, {{month, 1}, Rest}}; <<"Feb"/utf8, Rest@1/binary>> -> {ok, {{month, 2}, Rest@1}}; <<"Mar"/utf8, Rest@2/binary>> -> {ok, {{month, 3}, Rest@2}}; <<"Apr"/utf8, Rest@3/binary>> -> {ok, {{month, 4}, Rest@3}}; <<"May"/utf8, Rest@4/binary>> -> {ok, {{month, 5}, Rest@4}}; <<"Jun"/utf8, Rest@5/binary>> -> {ok, {{month, 6}, Rest@5}}; <<"Jul"/utf8, Rest@6/binary>> -> {ok, {{month, 7}, Rest@6}}; <<"Aug"/utf8, Rest@7/binary>> -> {ok, {{month, 8}, Rest@7}}; <<"Sep"/utf8, Rest@8/binary>> -> {ok, {{month, 9}, Rest@8}}; <<"Oct"/utf8, Rest@9/binary>> -> {ok, {{month, 10}, Rest@9}}; <<"Nov"/utf8, Rest@10/binary>> -> {ok, {{month, 11}, Rest@10}}; <<"Dec"/utf8, Rest@11/binary>> -> {ok, {{month, 12}, Rest@11}}; _ -> {error, nil} end; <<"MMMM"/utf8>> -> case Str of <<"January"/utf8, Rest@12/binary>> -> {ok, {{month, 1}, Rest@12}}; <<"February"/utf8, Rest@13/binary>> -> {ok, {{month, 2}, Rest@13}}; <<"March"/utf8, Rest@14/binary>> -> {ok, {{month, 3}, Rest@14}}; <<"April"/utf8, Rest@15/binary>> -> {ok, {{month, 4}, Rest@15}}; <<"May"/utf8, Rest@16/binary>> -> {ok, {{month, 5}, Rest@16}}; <<"June"/utf8, Rest@17/binary>> -> {ok, {{month, 6}, Rest@17}}; <<"July"/utf8, Rest@18/binary>> -> {ok, {{month, 7}, Rest@18}}; <<"August"/utf8, Rest@19/binary>> -> {ok, {{month, 8}, Rest@19}}; <<"September"/utf8, Rest@20/binary>> -> {ok, {{month, 9}, Rest@20}}; <<"October"/utf8, Rest@21/binary>> -> {ok, {{month, 10}, Rest@21}}; <<"November"/utf8, Rest@22/binary>> -> {ok, {{month, 11}, Rest@22}}; <<"December"/utf8, Rest@23/binary>> -> {ok, {{month, 12}, Rest@23}}; _ -> {error, nil} end; <<"D"/utf8>> -> consume_one_or_two_digits(Str, fun(Field@0) -> {day, Field@0} end); <<"DD"/utf8>> -> consume_two_digits(Str, fun(Field@0) -> {day, Field@0} end); <<"d"/utf8>> -> case Str of <<"0"/utf8, Rest@24/binary>> -> {ok, {passthrough, Rest@24}}; <<"1"/utf8, Rest@25/binary>> -> {ok, {passthrough, Rest@25}}; <<"2"/utf8, Rest@26/binary>> -> {ok, {passthrough, Rest@26}}; <<"3"/utf8, Rest@27/binary>> -> {ok, {passthrough, Rest@27}}; <<"4"/utf8, Rest@28/binary>> -> {ok, {passthrough, Rest@28}}; <<"5"/utf8, Rest@29/binary>> -> {ok, {passthrough, Rest@29}}; <<"6"/utf8, Rest@30/binary>> -> {ok, {passthrough, Rest@30}}; _ -> {error, nil} end; <<"dd"/utf8>> -> case Str of <<"Su"/utf8, Rest@31/binary>> -> {ok, {passthrough, Rest@31}}; <<"Mo"/utf8, Rest@32/binary>> -> {ok, {passthrough, Rest@32}}; <<"Tu"/utf8, Rest@33/binary>> -> {ok, {passthrough, Rest@33}}; <<"We"/utf8, Rest@34/binary>> -> {ok, {passthrough, Rest@34}}; <<"Th"/utf8, Rest@35/binary>> -> {ok, {passthrough, Rest@35}}; <<"Fr"/utf8, Rest@36/binary>> -> {ok, {passthrough, Rest@36}}; <<"Sa"/utf8, Rest@37/binary>> -> {ok, {passthrough, Rest@37}}; _ -> {error, nil} end; <<"ddd"/utf8>> -> case Str of <<"Sun"/utf8, Rest@38/binary>> -> {ok, {passthrough, Rest@38}}; <<"Mon"/utf8, Rest@39/binary>> -> {ok, {passthrough, Rest@39}}; <<"Tue"/utf8, Rest@40/binary>> -> {ok, {passthrough, Rest@40}}; <<"Wed"/utf8, Rest@41/binary>> -> {ok, {passthrough, Rest@41}}; <<"Thu"/utf8, Rest@42/binary>> -> {ok, {passthrough, Rest@42}}; <<"Fri"/utf8, Rest@43/binary>> -> {ok, {passthrough, Rest@43}}; <<"Sat"/utf8, Rest@44/binary>> -> {ok, {passthrough, Rest@44}}; _ -> {error, nil} end; <<"dddd"/utf8>> -> case Str of <<"Sunday"/utf8, Rest@45/binary>> -> {ok, {passthrough, Rest@45}}; <<"Monday"/utf8, Rest@46/binary>> -> {ok, {passthrough, Rest@46}}; <<"Tuesday"/utf8, Rest@47/binary>> -> {ok, {passthrough, Rest@47}}; <<"Wednesday"/utf8, Rest@48/binary>> -> {ok, {passthrough, Rest@48}}; <<"Thursday"/utf8, Rest@49/binary>> -> {ok, {passthrough, Rest@49}}; <<"Friday"/utf8, Rest@50/binary>> -> {ok, {passthrough, Rest@50}}; <<"Saturday"/utf8, Rest@51/binary>> -> {ok, {passthrough, Rest@51}}; _ -> {error, nil} end; <<"H"/utf8>> -> consume_one_or_two_digits(Str, fun(Field@0) -> {hour, Field@0} end); <<"HH"/utf8>> -> consume_two_digits(Str, fun(Field@0) -> {hour, Field@0} end); <<"h"/utf8>> -> consume_one_or_two_digits( Str, fun(Field@0) -> {twelve_hour, Field@0} end ); <<"hh"/utf8>> -> consume_two_digits(Str, fun(Field@0) -> {twelve_hour, Field@0} end); <<"a"/utf8>> -> case Str of <<"am"/utf8, Rest@52/binary>> -> {ok, {a_m_period, Rest@52}}; <<"pm"/utf8, Rest@53/binary>> -> {ok, {p_m_period, Rest@53}}; _ -> {error, nil} end; <<"A"/utf8>> -> case Str of <<"AM"/utf8, Rest@54/binary>> -> {ok, {a_m_period, Rest@54}}; <<"PM"/utf8, Rest@55/binary>> -> {ok, {p_m_period, Rest@55}}; _ -> {error, nil} end; <<"m"/utf8>> -> consume_one_or_two_digits( Str, fun(Field@0) -> {minute, Field@0} end ); <<"mm"/utf8>> -> consume_two_digits(Str, fun(Field@0) -> {minute, Field@0} end); <<"s"/utf8>> -> consume_one_or_two_digits( Str, fun(Field@0) -> {second, Field@0} end ); <<"ss"/utf8>> -> consume_two_digits(Str, fun(Field@0) -> {second, Field@0} end); <<"SSS"/utf8>> -> gleam@result:map( begin _pipe@2 = gleam@string:slice(Str, 0, 3), gleam_stdlib:parse_int(_pipe@2) end, fun(Milli) -> {{millisecond, Milli}, gleam@string:drop_start(Str, 3)} end ); <<"SSSS"/utf8>> -> gleam@result:map( begin _pipe@3 = gleam@string:slice(Str, 0, 6), gleam_stdlib:parse_int(_pipe@3) end, fun(Micro) -> {{microsecond, Micro}, gleam@string:drop_start(Str, 6)} end ); <<"z"/utf8>> -> gleam@result:try_recover( begin _pipe@4 = gleam@string:slice(Str, 0, 6), _pipe@6 = (fun(Offset) -> gleam@result:'try'( begin _pipe@5 = gleam@regexp:from_string( <<"[-+]\\d\\d:\\d\\d"/utf8>> ), gleam@result:replace_error(_pipe@5, nil) end, fun(Re) -> case gleam@regexp:check(Re, Offset) of true -> {ok, Offset}; false -> {error, nil} end end ) end)(_pipe@4), gleam@result:map( _pipe@6, fun(Offset@1) -> {{offset_str, Offset@1}, gleam@string:drop_start(Str, 6)} end ) end, fun(_) -> gleam@result:try_recover( begin _pipe@7 = gleam@string:slice(Str, 0, 5), _pipe@9 = (fun(Offset@2) -> gleam@result:'try'( begin _pipe@8 = gleam@regexp:from_string( <<"[-+]\\d\\d\\d\\d"/utf8>> ), gleam@result:replace_error(_pipe@8, nil) end, fun(Re@1) -> case gleam@regexp:check(Re@1, Offset@2) of true -> {ok, Offset@2}; false -> {error, nil} end end ) end)(_pipe@7), gleam@result:map( _pipe@9, fun(Offset@3) -> {{offset_str, Offset@3}, gleam@string:drop_start(Str, 5)} end ) end, fun(_) -> gleam@result:try_recover( begin _pipe@10 = gleam@string:slice(Str, 0, 3), _pipe@12 = (fun(Offset@4) -> gleam@result:'try'( begin _pipe@11 = gleam@regexp:from_string( <<"[-+]\\d\\d"/utf8>> ), gleam@result:replace_error( _pipe@11, nil ) end, fun(Re@2) -> case gleam@regexp:check( Re@2, Offset@4 ) of true -> {ok, Offset@4}; false -> {error, nil} end end ) end)(_pipe@10), gleam@result:map( _pipe@12, fun(Offset@5) -> {{offset_str, Offset@5}, gleam@string:drop_start(Str, 3)} end ) end, fun(_) -> gleam@result:try_recover( begin _pipe@13 = gleam@string:slice( Str, 0, 1 ), _pipe@14 = (fun(Offset@6) -> case (Offset@6 =:= <<"Z"/utf8>>) orelse (Offset@6 =:= <<"z"/utf8>>) of true -> {ok, Offset@6}; false -> {error, nil} end end)(_pipe@13), gleam@result:map( _pipe@14, fun(Offset@7) -> {{offset_str, Offset@7}, gleam@string:drop_start( Str, 1 )} end ) end, fun(_) -> {error, nil} end ) end ) end ) end ); <<"zz"/utf8>> -> case Str of <<"Z"/utf8>> -> {ok, {{offset_str, <<"Z"/utf8>>}, gleam@string:drop_start(Str, 1)}}; <<"z"/utf8>> -> {ok, {{offset_str, <<"z"/utf8>>}, gleam@string:drop_start(Str, 1)}}; _ -> {ok, {{offset_str, gleam@string:slice(Str, 0, 6)}, gleam@string:drop_start(Str, 6)}} end; <<"Z"/utf8>> -> {ok, {{offset_str, gleam@string:slice(Str, 0, 6)}, gleam@string:drop_start(Str, 6)}}; <<"ZZ"/utf8>> -> {ok, {{offset_str, gleam@string:slice(Str, 0, 5)}, gleam@string:drop_start(Str, 5)}}; <<"GMT"/utf8>> -> case Str =:= <<"GMT"/utf8>> of true -> {ok, {{offset_str, <<"Z"/utf8>>}, gleam@string:drop_start(Str, 3)}}; false -> {error, nil} end; Passthrough -> Fmt_length = string:length(Passthrough), Str_slice = gleam@string:slice(Str, 0, Fmt_length), case Str_slice =:= Passthrough of true -> {ok, {passthrough, gleam@string:drop_start(Str, Fmt_length)}}; false -> {error, nil} end end, gleam@result:map_error( _pipe@15, fun(_) -> <<"Unable to parse directive "/utf8, Fmt/binary>> end ). -file("src/tempo.gleam", 3375). ?DOC(false). -spec consume_format(binary(), binary()) -> {ok, {list(datetime_part()), binary()}} | {error, binary()}. consume_format(Str, Fmt) -> Re@1 = case gleam@regexp:from_string( <<"\\[([^\\]]+)\\]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|z{1,2}|Z{1,2}|S{3,4}|GMT|."/utf8>> ) of {ok, Re} -> Re; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"tempo"/utf8>>, function => <<"consume_format"/utf8>>, line => 3376, value => _assert_fail, start => 94296, 'end' => 94457, pattern_start => 94307, pattern_end => 94313}) end, _pipe = gleam@regexp:scan(Re@1, Fmt), gleam@list:fold(_pipe, {ok, {[], Str}}, fun(Acc, Match) -> case Acc of {ok, Acc@1} -> {Consumed, Input} = Acc@1, Res = case Match of {match, Content, []} -> consume_part(Content, Input); {match, _, [{some, Sub}]} -> case gleam_stdlib:string_starts_with(Input, Sub) of true -> {ok, {passthrough, gleam@string:drop_start( Input, string:length(Sub) )}}; false -> {error, <<<<"Input does not match expected escape sequence \""/utf8, Sub/binary>>/binary, "\""/utf8>>} end; {match, Content@1, _} -> {ok, {passthrough, gleam@string:drop_start( Input, string:length(Content@1) )}} end, case Res of {ok, {Part, Not_consumed}} -> {ok, {[Part | Consumed], Not_consumed}}; {error, Err} -> {error, Err} end; {error, Err@1} -> {error, Err@1} end end). -file("src/tempo.gleam", 3880). ?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", 3888). ?DOC(false). -spec unfreeze_time_ffi() -> nil. unfreeze_time_ffi() -> tempo_ffi:unfreeze_time(). -file("src/tempo.gleam", 3893). ?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", 3902). ?DOC(false). -spec unset_reference_time_ffi() -> nil. unset_reference_time_ffi() -> tempo_ffi:unset_reference_time(). -file("src/tempo.gleam", 3907). ?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", 3912). ?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", 3917). ?DOC(false). -spec add_warp_time_ffi(integer()) -> nil. add_warp_time_ffi(Microseconds) -> tempo_ffi:add_warp_time(Microseconds). -file("src/tempo.gleam", 3922). ?DOC(false). -spec reset_warp_time_ffi() -> nil. reset_warp_time_ffi() -> tempo_ffi:reset_warp_time(). -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", 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", 1365). ?DOC(false). -spec offset_from_string(binary()) -> {ok, offset()} | {error, tempo@error:offset_parse_error()}. offset_from_string(Offset_str) -> gleam@result:'try'(case Offset_str of <<"Z"/utf8>> -> {ok, {offset, 0}}; <<"z"/utf8>> -> {ok, {offset, 0}}; _ -> gleam@result:'try'( case gleam@string:split(Offset_str, <<":"/utf8>>) of [Hour, Minute] -> case {string:length(Hour), string:length(Minute)} of {3, 2} -> {ok, {gleam@string:slice(Hour, 0, 1), gleam@string:slice(Hour, 1, 2), Minute}}; {_, _} -> {error, {offset_invalid_format, Offset_str}} end; _ -> case string:length(Offset_str) of 5 -> {ok, {gleam@string:slice(Offset_str, 0, 1), gleam@string:slice(Offset_str, 1, 2), gleam@string:slice(Offset_str, 3, 2)}}; 3 -> {ok, {gleam@string:slice(Offset_str, 0, 1), gleam@string:slice(Offset_str, 1, 2), <<"0"/utf8>>}}; 2 -> {ok, {gleam@string:slice(Offset_str, 0, 1), gleam@string:slice(Offset_str, 1, 1), <<"0"/utf8>>}}; _ -> {error, {offset_invalid_format, Offset_str}} end end, fun(_use0) -> {Sign, Hour@1, Minute@1} = _use0, case {Sign, gleam_stdlib:parse_int(Hour@1), gleam_stdlib:parse_int(Minute@1)} of {_, {ok, 0}, {ok, 0}} -> {ok, {offset, 0}}; {<<"-"/utf8>>, {ok, Hour@2}, {ok, Minute@2}} when (Hour@2 =< 24) andalso (Minute@2 =< 60) -> {ok, {offset, - ((Hour@2 * 60) + Minute@2)}}; {<<"+"/utf8>>, {ok, Hour@3}, {ok, Minute@3}} when (Hour@3 =< 24) andalso (Minute@3 =< 60) -> {ok, {offset, (Hour@3 * 60) + Minute@3}}; {_, _, _} -> {error, {offset_invalid_format, Offset_str}} end end ) end, fun(Offset) -> _pipe = validate_offset(Offset), gleam@result:replace_error( _pipe, {offset_out_of_bounds, Offset_str} ) end). -file("src/tempo.gleam", 3823). ?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", 1844). -spec date_to_rata_die(date()) -> integer(). date_to_rata_die(Date) -> erlang:element(2, Date) + 719163. -file("src/tempo.gleam", 1537). ?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", 1721). -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 => 1749, value => _assert_fail, start => 47478, 'end' => 47518, pattern_start => 47489, pattern_end => 47498}) 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", 1521). ?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", 1531). ?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", 1563). ?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", 1568). ?DOC(false). -spec date_get_day(date()) -> integer(). date_get_day(Date) -> erlang:element(4, date_to_calendar_date(Date)). -file("src/tempo.gleam", 1597). ?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", 1189). ?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", 1613). ?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(_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", 1796). ?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", 1848). -spec date_from_rata_die(integer()) -> date(). date_from_rata_die(Rata_die) -> {date, Rata_die - 719163}. -file("src/tempo.gleam", 1801). ?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", 1526). ?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", 1694). ?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", 1573). ?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", 2869). -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", 2846). ?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", 3108). ?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) -> Empty_result = {none, none, none}, result_guard( gleam@regexp:from_string(<<"\\d{10,}"/utf8>>), Empty_result, fun(Serial_re) -> gleam@bool:guard( gleam@regexp:check(Serial_re, Str), Empty_result, fun() -> result_guard( gleam@regexp:from_string( <<"(\\d{4})[-_/\\.\\s,]{0,2}(\\d{1,2})[-_/\\.\\s,]{0,2}(\\d{1,2})"/utf8>> ), Empty_result, fun(Date_re) -> result_guard( gleam@regexp:from_string( <<"(\\d{1,2}|January|Jan|january|jan|February|Feb|february|feb|March|Mar|march|mar|April|Apr|april|apr|May|may|June|Jun|june|jun|July|Jul|july|jul|August|Aug|august|aug|September|Sep|september|sep|October|Oct|october|oct|November|Nov|november|nov|December|Dec|december|dec)[-_/\\.\\s,]{0,2}(\\d{1,2})(?:st|nd|rd|th)?[-_/\\.\\s,]{0,2}(\\d{4})"/utf8>> ), Empty_result, fun(Date_human_re) -> result_guard( gleam@regexp:from_string( <<"(\\d{1,2})[:_\\.\\s]{0,1}(\\d{1,2})[:_\\.\\s]{0,1}(\\d{0,2})[\\.]{0,1}(\\d{0,9})\\s*(AM|PM|am|pm)?"/utf8>> ), Empty_result, fun(Time_re) -> result_guard( gleam@regexp:from_string( <<"([-+]\\d{2}):{0,1}(\\d{0,2})?"/utf8>> ), Empty_result, fun(Offset_re) -> result_guard( gleam@regexp:from_string( <<"(?> ), Empty_result, fun(Offset_char_re) -> Unconsumed = Str, {Date@1, Unconsumed@1} = (case gleam@regexp:scan( Date_re, Unconsumed ) of [{match, Content, [{some, Year}, {some, Month}, {some, Day}]} | _] -> case {gleam_stdlib:parse_int( Year ), gleam_stdlib:parse_int( Month ), gleam_stdlib:parse_int( Day )} of {{ok, Year@1}, {ok, Month@1}, {ok, Day@1}} -> case new_date( Year@1, Month@1, Day@1 ) of {ok, Date} -> {{some, Date}, gleam@string:replace( Unconsumed, Content, <<""/utf8>> )}; _ -> {none, Unconsumed} end; {_, _, _} -> {none, Unconsumed} end; _ -> {none, Unconsumed} end), {Date@3, Unconsumed@2} = (case Date@1 of {some, D} -> {{some, D}, Unconsumed@1}; none -> case gleam@regexp:scan( Date_human_re, Unconsumed@1 ) of [{match, Content@1, [{some, Month@2}, {some, Day@2}, {some, Year@2}]} | _] -> case {gleam_stdlib:parse_int( Year@2 ), begin _pipe = gleam_stdlib:parse_int( Month@2 ), _pipe@1 = gleam@result:'try'( _pipe, fun month_from_int/1 ), gleam@result:try_recover( _pipe@1, fun( _ ) -> _pipe@2 = month_from_short_string( Month@2 ), gleam@result:try_recover( _pipe@2, fun( _ ) -> month_from_long_string( Month@2 ) end ) end ) end, gleam_stdlib:parse_int( Day@2 )} of {{ok, Year@3}, {ok, Month@3}, {ok, Day@3}} -> case new_date( Year@3, month_to_int( Month@3 ), Day@3 ) of {ok, Date@2} -> {{some, Date@2}, gleam@string:replace( Unconsumed@1, Content@1, <<""/utf8>> )}; _ -> {none, Unconsumed@1} end; {_, _, _} -> {none, Unconsumed@1} end; _ -> {none, Unconsumed@1} end end), {Offset@2, Unconsumed@3} = (case gleam@regexp:scan( Offset_re, Unconsumed@2 ) of [{match, Content@2, [{some, Hours}, {some, Minutes}]} | _] -> case {gleam_stdlib:parse_int( Hours ), gleam_stdlib:parse_int( Minutes )} of {{ok, Hour}, {ok, Minute}} -> case new_offset( duration_minutes( (Hour * 60) + Minute ) ) of {ok, Offset} -> {{some, Offset}, gleam@string:replace( Unconsumed@2, Content@2, <<""/utf8>> )}; _ -> {none, Unconsumed@2} end; {_, _} -> {none, Unconsumed@2} end; [{match, Content@3, [{some, Hours@1}, none]} | _] -> case gleam_stdlib:parse_int( Hours@1 ) of {ok, Hour@1} -> case new_offset( duration_minutes( Hour@1 * 60 ) ) of {ok, Offset@1} -> {{some, Offset@1}, gleam@string:replace( Unconsumed@2, Content@3, <<""/utf8>> )}; _ -> {none, Unconsumed@2} end; _ -> {none, Unconsumed@2} end; [{match, Content@3, [{some, Hours@1}]} | _] -> case gleam_stdlib:parse_int( Hours@1 ) of {ok, Hour@1} -> case new_offset( duration_minutes( Hour@1 * 60 ) ) of {ok, Offset@1} -> {{some, Offset@1}, gleam@string:replace( Unconsumed@2, Content@3, <<""/utf8>> )}; _ -> {none, Unconsumed@2} end; _ -> {none, Unconsumed@2} end; _ -> {none, Unconsumed@2} end), {Offset@3, Unconsumed@4} = (case Offset@2 of {some, O} -> {{some, O}, Unconsumed@3}; none -> case gleam@regexp:scan( Offset_char_re, Unconsumed@3 ) of [{match, Content@4, _} | _] -> {{some, {offset, 0}}, gleam@string:replace( Unconsumed@3, Content@4, <<""/utf8>> )}; _ -> {none, Unconsumed@3} end end), {Time, _} = begin Scan_results = gleam@regexp:scan( Time_re, Unconsumed@4 ), Adj_hour = case Scan_results of [{match, _, [_, _, _, _, {some, <<"PM"/utf8>>}]} | _] -> fun( _capture ) -> adjust_12_hour_to_24_hour( _capture, false ) end; [{match, _, [_, _, _, _, {some, <<"pm"/utf8>>}]} | _] -> fun( _capture@1 ) -> adjust_12_hour_to_24_hour( _capture@1, false ) end; [{match, _, [_, _, _, _, {some, <<"AM"/utf8>>}]} | _] -> fun( _capture@2 ) -> adjust_12_hour_to_24_hour( _capture@2, true ) end; [{match, _, [_, _, _, _, {some, <<"am"/utf8>>}]} | _] -> fun( _capture@3 ) -> adjust_12_hour_to_24_hour( _capture@3, true ) end; _ -> fun( Hour@2 ) -> Hour@2 end end, case Scan_results of [{match, Content@5, [{some, H}, {some, M}, {some, S}, {some, D@1} | _]} | _] -> case {gleam_stdlib:parse_int( H ), gleam_stdlib:parse_int( M ), gleam_stdlib:parse_int( S )} of {{ok, Hour@3}, {ok, Minute@1}, {ok, Second}} -> case {string:length( D@1 ), gleam_stdlib:parse_int( D@1 )} of {3, {ok, Milli}} -> case begin _pipe@3 = Adj_hour( Hour@3 ), new_time_milli( _pipe@3, Minute@1, Second, Milli ) end of {ok, Date@4} -> {{some, Date@4}, gleam@string:replace( Unconsumed@4, Content@5, <<""/utf8>> )}; _ -> {none, Unconsumed@4} end; {6, {ok, Micro}} -> case begin _pipe@4 = Adj_hour( Hour@3 ), new_time_micro( _pipe@4, Minute@1, Second, Micro ) end of {ok, Date@5} -> {{some, Date@5}, gleam@string:replace( Unconsumed@4, Content@5, <<""/utf8>> )}; _ -> {none, Unconsumed@4} end; {9, {ok, Nano}} -> case begin _pipe@5 = Adj_hour( Hour@3 ), new_time_micro( _pipe@5, Minute@1, Second, Nano div 1000 ) end of {ok, Date@6} -> {{some, Date@6}, gleam@string:replace( Unconsumed@4, Content@5, <<""/utf8>> )}; _ -> {none, Unconsumed@4} end; {_, _} -> {none, Unconsumed@4} end; {_, _, _} -> {none, Unconsumed@4} end; [{match, Content@6, [{some, H@1}, {some, M@1}, {some, S@1} | _]} | _] -> case {gleam_stdlib:parse_int( H@1 ), gleam_stdlib:parse_int( M@1 ), gleam_stdlib:parse_int( S@1 )} of {{ok, Hour@4}, {ok, Minute@2}, {ok, Second@1}} -> case begin _pipe@6 = Adj_hour( Hour@4 ), new_time( _pipe@6, Minute@2, Second@1 ) end of {ok, Date@7} -> {{some, Date@7}, gleam@string:replace( Unconsumed@4, Content@6, <<""/utf8>> )}; _ -> {none, Unconsumed@4} end; {_, _, _} -> {none, Unconsumed@4} end; [{match, Content@7, [{some, H@2}, {some, M@2} | _]} | _] -> case {gleam_stdlib:parse_int( H@2 ), gleam_stdlib:parse_int( M@2 )} of {{ok, Hour@5}, {ok, Minute@3}} -> case begin _pipe@7 = Adj_hour( Hour@5 ), new_time( _pipe@7, Minute@3, 0 ) end of {ok, Date@8} -> {{some, Date@8}, gleam@string:replace( Unconsumed@4, Content@7, <<""/utf8>> )}; _ -> {none, Unconsumed@4} end; {_, _} -> {none, Unconsumed@4} end; _ -> {none, Unconsumed@4} end end, {Date@3, Time, Offset@3} end ) end ) end ) end ) end ) end ) end ). -file("src/tempo.gleam", 3695). ?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", 2776). ?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", 2766). ?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", 2809). ?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", 1003). ?DOC(false). -spec datetime_format(date_time(), date_time_format()) -> binary(). datetime_format(Datetime, Format) -> Format_str = get_datetime_format_str(Format), Re@1 = case gleam@regexp:from_string( <<"\\[([^\\]]+)\\]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|z{1,2}|S{3,4}|GMT|."/utf8>> ) of {ok, Re} -> Re; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"tempo"/utf8>>, function => <<"datetime_format"/utf8>>, line => 1006, value => _assert_fail, start => 27536, 'end' => 27588, pattern_start => 27547, pattern_end => 27553}) end, _pipe = gleam@regexp:scan(Re@1, Format_str), _pipe@1 = lists:reverse(_pipe), _pipe@5 = gleam@list:fold(_pipe@1, [], fun(Acc, Match) -> case Match of {match, Content, []} -> [begin _pipe@2 = Content, _pipe@3 = date_replace_format( _pipe@2, erlang:element(2, Datetime) ), _pipe@4 = time_replace_format( _pipe@3, erlang:element(3, Datetime) ), offset_replace_format( _pipe@4, erlang:element(4, Datetime) ) end | Acc]; {match, _, [{some, Sub}]} -> [Sub | Acc]; {match, Content@1, _} -> [Content@1 | Acc] end end), gleam@string:join(_pipe@5, <<""/utf8>>). -file("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", 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", 1092). ?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", 1242). ?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", 1287). ?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", 1075). ?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", 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", 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", 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", 1033). ?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", 1039). ?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", 1044). ?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", 1049). ?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", 1054). ?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", 1059). ?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", 1064). ?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", 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", 1124). ?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", 2734). ?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", 2792). ?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.