Current section
Files
Jump to
Current section
Files
src/dateformat@internal@day.erl
-module(dateformat@internal@day).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([to_day_of_week/2, to_iso_week_of_year/1, to_weekday_string/1, to_weekday_short_string/1, to_weekday_shorter_string/1, to_day_of_year/1]).
-spec to_day_of_week(birl:time(), boolean()) -> integer().
to_day_of_week(Time, Iso) ->
case {birl:weekday(Time), Iso} of
{mon, _} ->
1;
{tue, _} ->
2;
{wed, _} ->
3;
{thu, _} ->
4;
{fri, _} ->
5;
{sat, _} ->
6;
{sun, false} ->
0;
{sun, true} ->
7
end.
-spec to_iso_week_of_year(birl:time()) -> integer().
to_iso_week_of_year(T) ->
Day_num = (to_day_of_week(T, false) + 6) rem 7,
Day = birl:get_day(T),
T@1 = birl:set_day(
T,
erlang:setelement(4, Day, (erlang:element(4, Day) - Day_num) + 3)
),
First_thursday = birl:to_unix_micro(T@1),
T@2 = birl:set_day(
T@1,
erlang:setelement(4, erlang:setelement(3, birl:get_day(T@1), 1), 1)
),
T@3 = case to_day_of_week(T@2, false) of
4 ->
T@2;
D ->
birl:set_day(
T@2,
erlang:setelement(
4,
erlang:setelement(3, birl:get_day(T@2), 1),
1 + (((4 - D) + 7) rem 7)
)
)
end,
1 + gleam@float:truncate(
gleam@float:ceiling(
gleam@int:to_float(First_thursday - birl:to_unix_micro(T@3)) / 604800000000.0
)
).
-spec to_weekday_string(birl:time()) -> binary().
to_weekday_string(Time) ->
case birl:weekday(Time) of
mon ->
<<"Monday"/utf8>>;
tue ->
<<"Tuesday"/utf8>>;
wed ->
<<"Wednesday"/utf8>>;
thu ->
<<"Thursday"/utf8>>;
fri ->
<<"Friday"/utf8>>;
sat ->
<<"Saturday"/utf8>>;
sun ->
<<"Sunday"/utf8>>
end.
-spec to_weekday_short_string(birl:time()) -> binary().
to_weekday_short_string(Time) ->
case birl:weekday(Time) of
mon ->
<<"Mon"/utf8>>;
tue ->
<<"Tue"/utf8>>;
wed ->
<<"Wed"/utf8>>;
thu ->
<<"Thu"/utf8>>;
fri ->
<<"Fri"/utf8>>;
sat ->
<<"Sat"/utf8>>;
sun ->
<<"Sun"/utf8>>
end.
-spec to_weekday_shorter_string(birl:time()) -> binary().
to_weekday_shorter_string(Time) ->
case birl:weekday(Time) of
mon ->
<<"Mo"/utf8>>;
tue ->
<<"Tu"/utf8>>;
wed ->
<<"We"/utf8>>;
thu ->
<<"Th"/utf8>>;
fri ->
<<"Fr"/utf8>>;
sat ->
<<"Sa"/utf8>>;
sun ->
<<"Su"/utf8>>
end.
-spec to_day_of_year(birl:time()) -> integer().
to_day_of_year(T2) ->
Time = {time_of_day, 0, 0, 0, 0},
T2@1 = begin
_pipe = T2,
birl:set_time_of_day(_pipe, Time)
end,
Day = begin
_pipe@1 = T2@1,
birl:get_day(_pipe@1)
end,
T1 = begin
_pipe@2 = T2@1,
_pipe@3 = birl:set_day(_pipe@2, {day, erlang:element(2, Day), 1, 1}),
birl:set_time_of_day(_pipe@3, Time)
end,
Duration_micro = begin
_pipe@4 = T2@1,
birl:to_unix_micro(_pipe@4)
end
- begin
_pipe@5 = T1,
birl:to_unix_micro(_pipe@5)
end,
1 + (case 86400000000 of
0 -> 0;
Gleam@denominator -> Duration_micro div Gleam@denominator
end).