Current section
Files
Jump to
Current section
Files
src/tempo@date.erl
-module(tempo@date).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([new/3, get_year/1, get_month/1, get_day/1, to_string/1, parse/2, parse_any/1, from_tuple/1, from_string/1, literal/1, to_tuple/1, from_dynamic_string/1, from_unix_utc/1, current_local/0, current_utc/0, to_unix_utc/1, from_unix_milli_utc/1, to_unix_milli_utc/1, from_unix_micro_utc/1, to_unix_micro_utc/1, compare/2, is_earlier/2, is_earlier_or_equal/2, is_equal/2, is_later/2, is_later_or_equal/2, difference/2, as_period/2, add/2, subtract/2, to_day_of_week_number/1, to_day_of_week/1, day_of_week_to_short_string/1, day_of_week_to_long_string/1, replace_format/2, format/2, next_day_of_week/2, prior_day_of_week/2, is_weekend/1, first_of_month/1, last_of_month/1]).
-export_type([day_of_week/0]).
-type day_of_week() :: sun | mon | tue | wed | thu | fri | sat.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 74).
-spec new(integer(), integer(), integer()) -> {ok, tempo:date()} |
{error, tempo:error()}.
new(Year, Month, Day) ->
tempo:new_date(Year, Month, Day).
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 154).
-spec get_year(tempo:date()) -> integer().
get_year(Date) ->
_pipe = Date,
tempo:date_get_year(_pipe).
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 167).
-spec get_month(tempo:date()) -> tempo:month().
get_month(Date) ->
_pipe = Date,
tempo:date_get_month(_pipe).
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 180).
-spec get_day(tempo:date()) -> integer().
get_day(Date) ->
_pipe = Date,
tempo:date_get_day(_pipe).
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 223).
-spec split_int_tuple(binary(), binary()) -> {ok,
{integer(), integer(), integer()}} |
{error, tempo:error()}.
split_int_tuple(Date, Delim) ->
_pipe = gleam@string:split(Date, Delim),
_pipe@1 = gleam@list:map(_pipe, fun gleam@int:parse/1),
_pipe@2 = gleam@result:all(_pipe@1),
_pipe@3 = gleam@result:'try'(_pipe@2, fun(Date@1) -> case Date@1 of
[Year, Month, Day] ->
{ok, {Year, Month, Day}};
_ ->
{error, nil}
end end),
gleam@result:replace_error(_pipe@3, date_invalid_format).
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 248).
-spec to_string(tempo:date()) -> binary().
to_string(Date) ->
_pipe@6 = gleam@string_builder:from_strings(
[gleam@int:to_string(
begin
_pipe = Date,
tempo:date_get_year(_pipe)
end
),
<<"-"/utf8>>,
begin
_pipe@2 = tempo@month:to_int(
begin
_pipe@1 = Date,
tempo:date_get_month(_pipe@1)
end
),
_pipe@3 = gleam@int:to_string(_pipe@2),
gleam@string:pad_left(_pipe@3, 2, <<"0"/utf8>>)
end,
<<"-"/utf8>>,
begin
_pipe@5 = gleam@int:to_string(
begin
_pipe@4 = Date,
tempo:date_get_day(_pipe@4)
end
),
gleam@string:pad_left(_pipe@5, 2, <<"0"/utf8>>)
end]
),
gleam@string_builder:to_string(_pipe@6).
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 286).
-spec parse(binary(), binary()) -> {ok, tempo:date()} | {error, tempo:error()}.
parse(Str, Fmt) ->
gleam@result:'try'(
tempo:consume_format(Str, Fmt),
fun(_use0) ->
{Parts, _} = _use0,
tempo:find_date(Parts)
end
).
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 307).
-spec parse_any(binary()) -> {ok, tempo:date()} | {error, tempo:error()}.
parse_any(Str) ->
case tempo:parse_any(Str) of
{ok, {{some, Date}, _, _}} ->
{ok, Date};
{ok, {none, _, _}} ->
{error, parse_missing_date};
{error, Err} ->
{error, Err}
end.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 460).
-spec from_tuple({integer(), integer(), integer()}) -> {ok, tempo:date()} |
{error, tempo:error()}.
from_tuple(Date) ->
tempo:date_from_tuple(Date).
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 204).
-spec from_string(binary()) -> {ok, tempo:date()} | {error, tempo:error()}.
from_string(Date) ->
_pipe = split_int_tuple(Date, <<"-"/utf8>>),
_pipe@1 = gleam@result:try_recover(
_pipe,
fun(_) -> split_int_tuple(Date, <<"/"/utf8>>) end
),
_pipe@2 = gleam@result:try_recover(
_pipe@1,
fun(_) -> split_int_tuple(Date, <<"."/utf8>>) end
),
_pipe@3 = gleam@result:try_recover(
_pipe@2,
fun(_) -> split_int_tuple(Date, <<"_"/utf8>>) end
),
_pipe@4 = gleam@result:try_recover(
_pipe@3,
fun(_) -> split_int_tuple(Date, <<" "/utf8>>) end
),
_pipe@8 = gleam@result:try_recover(
_pipe@4,
fun(_) ->
Year = begin
_pipe@5 = gleam@string:slice(Date, 0, 4),
gleam@int:parse(_pipe@5)
end,
Month = begin
_pipe@6 = gleam@string:slice(Date, 4, 2),
gleam@int:parse(_pipe@6)
end,
Day = begin
_pipe@7 = gleam@string:slice(Date, 6, 2),
gleam@int:parse(_pipe@7)
end,
case {Year, Month, Day} of
{{ok, Year@1}, {ok, Month@1}, {ok, Day@1}} ->
{ok, {Year@1, Month@1, Day@1}};
{_, _, _} ->
{error, date_invalid_format}
end
end
),
gleam@result:'try'(_pipe@8, fun from_tuple/1).
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 108).
-spec literal(binary()) -> tempo:date().
literal(Date) ->
case from_string(Date) of
{ok, Date@1} ->
Date@1;
{error, date_invalid_format} ->
erlang:error(#{gleam_error => panic,
message => <<"Invalid date literal format"/utf8>>,
module => <<"tempo/date"/utf8>>,
function => <<"literal"/utf8>>,
line => 111});
{error, date_out_of_bounds} ->
erlang:error(#{gleam_error => panic,
message => <<"Invalid date literal value"/utf8>>,
module => <<"tempo/date"/utf8>>,
function => <<"literal"/utf8>>,
line => 112});
{error, _} ->
erlang:error(#{gleam_error => panic,
message => <<"Invalid date literal"/utf8>>,
module => <<"tempo/date"/utf8>>,
function => <<"literal"/utf8>>,
line => 113})
end.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 474).
-spec to_tuple(tempo:date()) -> {integer(), integer(), integer()}.
to_tuple(Date) ->
{begin
_pipe = Date,
tempo:date_get_year(_pipe)
end,
tempo@month:to_int(
begin
_pipe@1 = Date,
tempo:date_get_month(_pipe@1)
end
),
begin
_pipe@2 = Date,
tempo:date_get_day(_pipe@2)
end}.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 504).
-spec from_dynamic_string(gleam@dynamic:dynamic_()) -> {ok, tempo:date()} |
{error, list(gleam@dynamic:decode_error())}.
from_dynamic_string(Dynamic_string) ->
gleam@result:'try'(
gleam@dynamic:string(Dynamic_string),
fun(Dt) -> case from_string(Dt) of
{ok, Date} ->
{ok, Date};
{error, Tempo_error} ->
{error,
[{decode_error,
<<"tempo.Date"/utf8>>,
<<(case Tempo_error of
date_invalid_format ->
<<"Invalid format: "/utf8>>;
date_out_of_bounds ->
<<"Date out of bounds: "/utf8>>;
month_out_of_bounds ->
<<"Month out of bounds: "/utf8>>;
_ ->
<<""/utf8>>
end)/binary, Dt/binary>>,
[]}]}
end end
).
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 545).
-spec from_unix_utc(integer()) -> tempo:date().
from_unix_utc(Unix_ts) ->
Z = (Unix_ts div 86400) + 719468,
Era = case Z >= 0 of
true ->
Z;
false ->
Z - 146096
end div 146097,
Doe = Z - (Era * 146097),
Yoe = (((Doe - (Doe div 1460)) + (Doe div 36524)) - (Doe div 146096)) div 365,
Y = Yoe + (Era * 400),
Doy = Doe - (((365 * Yoe) + (Yoe div 4)) - (Yoe div 100)),
Mp = ((5 * Doy) + 2) div 153,
D = (Doy - (((153 * Mp) + 2) div 5)) + 1,
M = Mp + case Mp < 10 of
true ->
3;
false ->
-9
end,
Y@1 = Y + gleam@bool:to_int(M =< 2),
_assert_subject = tempo@month:from_int(M),
{ok, Month} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"tempo/date"/utf8>>,
function => <<"from_unix_utc"/utf8>>,
line => 567})
end,
tempo:date(Y@1, Month, D).
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 126).
-spec current_local() -> tempo:date().
current_local() ->
_pipe = (tempo_ffi:now() + tempo@offset:local_nano()) div 1000000000,
from_unix_utc(_pipe).
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 140).
-spec current_utc() -> tempo:date().
current_utc() ->
_pipe = tempo_ffi:now() div 1000000000,
from_unix_utc(_pipe).
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 588).
-spec to_unix_utc(tempo:date()) -> integer().
to_unix_utc(Date) ->
Full_years_since_epoch = tempo:date_get_year(Date) - 1970,
Full_elapsed_leap_years_since_epoch = (Full_years_since_epoch + 1) div 4,
Full_elapsed_non_leap_years_since_epoch = Full_years_since_epoch - Full_elapsed_leap_years_since_epoch,
Year_sec = (Full_elapsed_non_leap_years_since_epoch * 31536000) + (Full_elapsed_leap_years_since_epoch
* 31622400),
Feb_milli = case tempo@year:is_leap_year(
begin
_pipe = Date,
tempo:date_get_year(_pipe)
end
) of
true ->
2505600;
false ->
2419200
end,
Month_sec = case begin
_pipe@1 = Date,
tempo:date_get_month(_pipe@1)
end of
jan ->
0;
feb ->
2678400;
mar ->
2678400 + Feb_milli;
apr ->
5356800 + Feb_milli;
may ->
7948800 + Feb_milli;
jun ->
10627200 + Feb_milli;
jul ->
13219200 + Feb_milli;
aug ->
15897600 + Feb_milli;
sep ->
18576000 + Feb_milli;
oct ->
21168000 + Feb_milli;
nov ->
23846400 + Feb_milli;
dec ->
26438400 + Feb_milli
end,
Day_sec = (tempo:date_get_day(Date) - 1) * 86400,
(Year_sec + Month_sec) + Day_sec.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 646).
-spec from_unix_milli_utc(integer()) -> tempo:date().
from_unix_milli_utc(Unix_ts) ->
from_unix_utc(Unix_ts div 1000).
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 666).
-spec to_unix_milli_utc(tempo:date()) -> integer().
to_unix_milli_utc(Date) ->
to_unix_utc(Date) * 1000.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 687).
-spec from_unix_micro_utc(integer()) -> tempo:date().
from_unix_micro_utc(Unix_ts) ->
from_unix_utc(Unix_ts div 1000000).
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 707).
-spec to_unix_micro_utc(tempo:date()) -> integer().
to_unix_micro_utc(Date) ->
to_unix_utc(Date) * 1000000.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 732).
-spec compare(tempo:date(), tempo:date()) -> gleam@order:order().
compare(A, B) ->
case begin
_pipe = A,
tempo:date_get_year(_pipe)
end
=:= begin
_pipe@1 = B,
tempo:date_get_year(_pipe@1)
end of
true ->
case begin
_pipe@2 = A,
tempo:date_get_month(_pipe@2)
end
=:= begin
_pipe@3 = B,
tempo:date_get_month(_pipe@3)
end of
true ->
case begin
_pipe@4 = A,
tempo:date_get_day(_pipe@4)
end
=:= begin
_pipe@5 = B,
tempo:date_get_day(_pipe@5)
end of
true ->
eq;
false ->
gleam@int:compare(
begin
_pipe@6 = A,
tempo:date_get_day(_pipe@6)
end,
begin
_pipe@7 = B,
tempo:date_get_day(_pipe@7)
end
)
end;
false ->
gleam@int:compare(
tempo@month:to_int(
begin
_pipe@8 = A,
tempo:date_get_month(_pipe@8)
end
),
tempo@month:to_int(
begin
_pipe@9 = B,
tempo:date_get_month(_pipe@9)
end
)
)
end;
false ->
gleam@int:compare(
begin
_pipe@10 = A,
tempo:date_get_year(_pipe@10)
end,
begin
_pipe@11 = B,
tempo:date_get_year(_pipe@11)
end
)
end.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 767).
-spec is_earlier(tempo:date(), tempo:date()) -> boolean().
is_earlier(A, B) ->
compare(A, B) =:= lt.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 785).
-spec is_earlier_or_equal(tempo:date(), tempo:date()) -> boolean().
is_earlier_or_equal(A, B) ->
(compare(A, B) =:= lt) orelse (compare(A, B) =:= eq).
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 798).
-spec is_equal(tempo:date(), tempo:date()) -> boolean().
is_equal(A, B) ->
compare(A, B) =:= eq.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 817).
-spec is_later(tempo:date(), tempo:date()) -> boolean().
is_later(A, B) ->
compare(A, B) =:= gt.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 836).
-spec is_later_or_equal(tempo:date(), tempo:date()) -> boolean().
is_later_or_equal(A, B) ->
(compare(A, B) =:= gt) orelse (compare(A, B) =:= eq).
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 858).
-spec difference(tempo:date(), tempo:date()) -> tempo:period().
difference(A, B) ->
{Start, End} = case begin
_pipe = A,
is_earlier_or_equal(_pipe, B)
end of
true ->
{A, B};
false ->
{B, A}
end,
{naive_period,
tempo:naive_datetime(Start, tempo:time(0, 0, 0, 0, sec)),
tempo:naive_datetime(End, tempo:time(0, 0, 0, 0, sec))}.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 894).
-spec as_period(tempo:date(), tempo:date()) -> tempo:period().
as_period(Start, End) ->
{Start@1, End@1} = case begin
_pipe = Start,
is_earlier_or_equal(_pipe, End)
end of
true ->
{Start, End};
false ->
{End, Start}
end,
{naive_period,
tempo:naive_datetime(Start@1, tempo:time(0, 0, 0, 0, sec)),
tempo:naive_datetime(End@1, tempo:time(24, 0, 0, 0, sec))}.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 927).
-spec add(tempo:date(), integer()) -> tempo:date().
add(Date, Days) ->
Days_left_this_month = tempo@month:days(
begin
_pipe = Date,
tempo:date_get_month(_pipe)
end,
begin
_pipe@1 = Date,
tempo:date_get_year(_pipe@1)
end
)
- tempo:date_get_day(Date),
case Days =< Days_left_this_month of
true ->
tempo:date(
begin
_pipe@2 = Date,
tempo:date_get_year(_pipe@2)
end,
begin
_pipe@3 = Date,
tempo:date_get_month(_pipe@3)
end,
begin
_pipe@4 = Date,
tempo:date_get_day(_pipe@4)
end
+ Days
);
false ->
Next_month = tempo@month:next(
begin
_pipe@5 = Date,
tempo:date_get_month(_pipe@5)
end
),
Year = case Next_month =:= jan of
true ->
begin
_pipe@6 = Date,
tempo:date_get_year(_pipe@6)
end
+ 1;
false ->
_pipe@7 = Date,
tempo:date_get_year(_pipe@7)
end,
add(
tempo:date(Year, Next_month, 1),
(Days - Days_left_this_month) - 1
)
end.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 969).
-spec subtract(tempo:date(), integer()) -> tempo:date().
subtract(Date, Days) ->
case Days < begin
_pipe = Date,
tempo:date_get_day(_pipe)
end of
true ->
tempo:date(
begin
_pipe@1 = Date,
tempo:date_get_year(_pipe@1)
end,
begin
_pipe@2 = Date,
tempo:date_get_month(_pipe@2)
end,
begin
_pipe@3 = Date,
tempo:date_get_day(_pipe@3)
end
- Days
);
false ->
Prior_month = tempo@month:prior(
begin
_pipe@4 = Date,
tempo:date_get_month(_pipe@4)
end
),
Year = case Prior_month =:= dec of
true ->
begin
_pipe@5 = Date,
tempo:date_get_year(_pipe@5)
end
- 1;
false ->
_pipe@6 = Date,
tempo:date_get_year(_pipe@6)
end,
subtract(
tempo:date(
Year,
Prior_month,
tempo@month:days(Prior_month, Year)
),
Days - tempo:date_get_day(Date)
)
end.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 1002).
-spec to_day_of_week_number(tempo:date()) -> integer().
to_day_of_week_number(Date) ->
Year_code = begin
_pipe = tempo:date_get_year(Date) rem 100,
(fun(Short_year) -> (Short_year + (Short_year div 4)) rem 7 end)(_pipe)
end,
Month_code = case begin
_pipe@1 = Date,
tempo:date_get_month(_pipe@1)
end of
jan ->
0;
feb ->
3;
mar ->
3;
apr ->
6;
may ->
1;
jun ->
4;
jul ->
6;
aug ->
2;
sep ->
5;
oct ->
0;
nov ->
3;
dec ->
5
end,
Century_code = case begin
_pipe@2 = Date,
tempo:date_get_year(_pipe@2)
end of
Year when Year < 1752 ->
0;
Year@1 when Year@1 < 1800 ->
4;
Year@2 when Year@2 < 1900 ->
2;
Year@3 when Year@3 < 2000 ->
0;
Year@4 when Year@4 < 2100 ->
6;
Year@5 when Year@5 < 2200 ->
4;
Year@6 when Year@6 < 2300 ->
2;
Year@7 when Year@7 < 2400 ->
4;
_ ->
0
end,
Leap_year_code = case tempo@year:is_leap_year(
begin
_pipe@3 = Date,
tempo:date_get_year(_pipe@3)
end
) of
true ->
case begin
_pipe@4 = Date,
tempo:date_get_month(_pipe@4)
end of
jan ->
1;
feb ->
1;
_ ->
0
end;
false ->
0
end,
((((Year_code + Month_code) + Century_code) + tempo:date_get_day(Date)) - Leap_year_code)
rem 7.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 1063).
-spec to_day_of_week(tempo:date()) -> day_of_week().
to_day_of_week(Date) ->
case to_day_of_week_number(Date) of
0 ->
sun;
1 ->
mon;
2 ->
tue;
3 ->
wed;
4 ->
thu;
5 ->
fri;
6 ->
sat;
_ ->
erlang:error(#{gleam_error => panic,
message => <<"Invalid day of week found after modulo by 7"/utf8>>,
module => <<"tempo/date"/utf8>>,
function => <<"to_day_of_week"/utf8>>,
line => 1072})
end.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 1084).
-spec day_of_week_to_short_string(day_of_week()) -> binary().
day_of_week_to_short_string(Day_of_week) ->
case Day_of_week of
sun ->
<<"Sun"/utf8>>;
mon ->
<<"Mon"/utf8>>;
tue ->
<<"Tue"/utf8>>;
wed ->
<<"Wed"/utf8>>;
thu ->
<<"Thu"/utf8>>;
fri ->
<<"Fri"/utf8>>;
sat ->
<<"Sat"/utf8>>
end.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 1104).
-spec day_of_week_to_long_string(day_of_week()) -> binary().
day_of_week_to_long_string(Day_of_week) ->
case Day_of_week of
sun ->
<<"Sunday"/utf8>>;
mon ->
<<"Monday"/utf8>>;
tue ->
<<"Tuesday"/utf8>>;
wed ->
<<"Wednesday"/utf8>>;
thu ->
<<"Thursday"/utf8>>;
fri ->
<<"Friday"/utf8>>;
sat ->
<<"Saturday"/utf8>>
end.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 379).
-spec replace_format(binary(), tempo:date()) -> binary().
replace_format(Content, Date) ->
case Content of
<<"YY"/utf8>> ->
_pipe = Date,
_pipe@1 = get_year(_pipe),
_pipe@2 = gleam@int:to_string(_pipe@1),
_pipe@3 = gleam@string:pad_left(_pipe@2, 2, <<"0"/utf8>>),
gleam@string:slice(_pipe@3, -2, 2);
<<"YYYY"/utf8>> ->
_pipe@4 = Date,
_pipe@5 = get_year(_pipe@4),
_pipe@6 = gleam@int:to_string(_pipe@5),
gleam@string:pad_left(_pipe@6, 4, <<"0"/utf8>>);
<<"M"/utf8>> ->
_pipe@7 = Date,
_pipe@8 = get_month(_pipe@7),
_pipe@9 = tempo@month:to_int(_pipe@8),
gleam@int:to_string(_pipe@9);
<<"MM"/utf8>> ->
_pipe@10 = Date,
_pipe@11 = get_month(_pipe@10),
_pipe@12 = tempo@month:to_int(_pipe@11),
_pipe@13 = gleam@int:to_string(_pipe@12),
gleam@string:pad_left(_pipe@13, 2, <<"0"/utf8>>);
<<"MMM"/utf8>> ->
_pipe@14 = Date,
_pipe@15 = get_month(_pipe@14),
tempo@month:to_short_string(_pipe@15);
<<"MMMM"/utf8>> ->
_pipe@16 = Date,
_pipe@17 = get_month(_pipe@16),
tempo@month:to_long_string(_pipe@17);
<<"D"/utf8>> ->
_pipe@18 = Date,
_pipe@19 = get_day(_pipe@18),
gleam@int:to_string(_pipe@19);
<<"DD"/utf8>> ->
_pipe@20 = Date,
_pipe@21 = get_day(_pipe@20),
_pipe@22 = gleam@int:to_string(_pipe@21),
gleam@string:pad_left(_pipe@22, 2, <<"0"/utf8>>);
<<"d"/utf8>> ->
_pipe@23 = Date,
_pipe@24 = to_day_of_week_number(_pipe@23),
gleam@int:to_string(_pipe@24);
<<"dd"/utf8>> ->
_pipe@25 = Date,
_pipe@26 = to_day_of_week(_pipe@25),
_pipe@27 = day_of_week_to_short_string(_pipe@26),
gleam@string:slice(_pipe@27, 0, 2);
<<"ddd"/utf8>> ->
_pipe@28 = Date,
_pipe@29 = to_day_of_week(_pipe@28),
day_of_week_to_short_string(_pipe@29);
<<"dddd"/utf8>> ->
_pipe@30 = Date,
_pipe@31 = to_day_of_week(_pipe@30),
day_of_week_to_long_string(_pipe@31);
_ ->
Content
end.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 357).
-spec format(tempo:date(), binary()) -> binary().
format(Date, Fmt) ->
_assert_subject = gleam@regex: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|SSSSS|SSSS|SSS|."/utf8>>
),
{ok, Re} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"tempo/date"/utf8>>,
function => <<"format"/utf8>>,
line => 358})
end,
_pipe = gleam@regex:scan(Re, Fmt),
_pipe@1 = lists:reverse(_pipe),
_pipe@2 = gleam@list:fold(_pipe@1, [], fun(Acc, Match) -> case Match of
{match, Content, []} ->
[replace_format(Content, Date) | Acc];
{match, _, [{some, Sub}]} ->
[Sub | Acc];
{match, Content@1, _} ->
[Content@1 | Acc]
end end),
gleam@string:join(_pipe@2, <<""/utf8>>).
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 1132).
-spec next_day_of_week(tempo:date(), day_of_week()) -> tempo:date().
next_day_of_week(Date, Dow) ->
Next = begin
_pipe = Date,
add(_pipe, 1)
end,
case begin
_pipe@1 = Next,
to_day_of_week(_pipe@1)
end
=:= Dow of
true ->
Next;
false ->
next_day_of_week(Next, Dow)
end.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 1160).
-spec prior_day_of_week(tempo:date(), day_of_week()) -> tempo:date().
prior_day_of_week(Date, Dow) ->
Prior = begin
_pipe = Date,
subtract(_pipe, 1)
end,
case begin
_pipe@1 = Prior,
to_day_of_week(_pipe@1)
end
=:= Dow of
true ->
Prior;
false ->
prior_day_of_week(Prior, Dow)
end.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 1181).
-spec is_weekend(tempo:date()) -> boolean().
is_weekend(Date) ->
case to_day_of_week(Date) of
sat ->
true;
sun ->
true;
_ ->
false
end.
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 1197).
-spec first_of_month(tempo:date()) -> tempo:date().
first_of_month(Date) ->
tempo:date(
begin
_pipe = Date,
tempo:date_get_year(_pipe)
end,
begin
_pipe@1 = Date,
tempo:date_get_month(_pipe@1)
end,
1
).
-file("/home/john/Repos/tempo/src/tempo/date.gleam", 1210).
-spec last_of_month(tempo:date()) -> tempo:date().
last_of_month(Date) ->
tempo:date(
begin
_pipe = Date,
tempo:date_get_year(_pipe)
end,
begin
_pipe@1 = Date,
tempo:date_get_month(_pipe@1)
end,
tempo@month:days(
begin
_pipe@2 = Date,
tempo:date_get_month(_pipe@2)
end,
begin
_pipe@3 = Date,
tempo:date_get_year(_pipe@3)
end
)
).